高さが可変のEditTextの上に、同じ大きさのViewを被せようとしていますがうまい方法が見つかりません。
RelativeLayoutを使用して下記のように実装しようとしましたが、
親が"wrap_content"になっている時に子を"match_parent"にすると、子の高さが0になってしまいます。
xml
1<RelativeLayout 2 android:id="@+id/container" 3 android:layout_width="wrap_content" 4 android:layout_height="wrap_content"> 5 <EditText 6 android:id="@+id/edit_text" 7 android:layout_width="match_parent" 8 android:layout_height="wrap_content" 9 android:minHeight="40dp"/> 10 <MyView 11 android:id="@+id/cover_view" 12 android:layout_width="match_parent" 13 android:layout_height="match_parent" 14 android:background="@android:color/holo_orange_light" 15 android:alpha="0.3"/> 16</RelativeLayout>
また、EditTextのonSizeChangedの際にViewの大きさを設定しなおす方法も試しましたが、そのタイミングでは設定した値がすぐに反映されず、次にonSizeChangedが呼ばれるときに直前の大きさになってしまいます。
MyViewの下記の関数で大きさを設定しています。
このときheightには正しい値が入っていますが、画面に変更が反映されません。
Java
1// MyView class内 2public void changeHeight(int height){ 3 RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) this.getLayoutParams(); 4 params.height = height; 5 setLayoutParams(params); 6 requestLayout(); 7}
何か良い方法がありますでしょうか?
よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。