Activity Layout を LinearLayout から RelativeLayout に変更しましたが、次のエラーが発生します:-
09-18 16:18:07.949: E/AndroidRuntime(635): java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams
最後の EditText の align_parentBottom プロパティを除いて、LinearLayout でもすべて正常に動作しています。一番下にあるはずです。
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
LayoutParams params = new LayoutParams(metrics.widthPixels/3, LayoutParams.WRAP_CONTENT);
selectOne.setLayoutParams(params);
selectTwo.setLayoutParams(params);
selectThree.setLayoutParams(params);
selectOne、selectTwo、および Three は、ページの上部にあるボタンです。この行でのみエラーが発生します。
私の活動xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background_violet"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/selectLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/emptyText1"
android:layout_alignParentTop="true"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/selectReleased"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/not_selected_button"
android:gravity="center"
android:text="Released"
android:textStyle="normal" />
<Button
android:id="@+id/selectReleasing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/selected_button"
android:gravity="center"
android:text="This Weekend"
android:textStyle="normal" />
<Button
android:id="@+id/selectUpcoming"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/not_selected_button"
android:gravity="center"
android:text="Upcoming"
android:textStyle="normal" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/emptyText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="5px" />
</LinearLayout>
<LinearLayout
android:id="@+id/monthLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/emptyText2"
android:layout_below="@+id/emptyText1"
android:layout_gravity="center"
android:gravity="center" >
<Button
android:id="@+id/select_month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fadingEdge="horizontal"
android:textColor="#000000"
android:textStyle="bold"
android:visibility="visible" >
</Button>
</LinearLayout>
<LinearLayout
android:id="@+id/emptyText2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="5px" />
</LinearLayout>
<LinearLayout
android:id="@+id/msgTxt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/selectAfterLayout"
android:layout_below="@+id/emptyText2"
android:layout_gravity="center"
android:gravity="center" >
<TextView
android:id="@+id/msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:visibility="invisible" />
</LinearLayout>
<LinearLayout
android:id="@+id/selectAfterLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/aboveLay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<ListView
android:id="@+id/moviesLV"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0" >
</ListView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/textTest111"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
</LinearLayout>
</RelativeLayout>
次のエラーが発生しました:-
09-18 17:47:52.869: E/AndroidRuntime(1122): FATAL EXCEPTION: main 09-18 17:47:52.869: E/AndroidRuntime(1122): java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams 09-18 17:47:52.869: E/AndroidRuntime(1122): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:654) 09-18 17:47:52.869: E/AndroidRuntime(1122): at android.widget.LinearLayout.onMeasure(LinearLayout.java:306) 09-18 17:47:52.869: E/AndroidRuntime(1122): at android.view.View.measure(View.java:8171) 09-18 17:47:52.869: E/AndroidRuntime(1122): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 09-18 17:47:52.869: E/AndroidRuntime(1122): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012) 09-18 17:47:52.869: E/AndroidRuntime(1122): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381) 09-18 17:47:52.869: E/AndroidRuntime(1122): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304) 09-18 17:47:52.869: E/AndroidRuntime(1122): at android.view.View.measure(View.java:8171) 09-18 17:47:52.869: E/AndroidRuntime(1122): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:578) 09-18 17:47:52.869: E/AndroidRuntime(1122): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:362) 09-18 17:47:52.869: E/AndroidRuntime(1122): at android.view.View.measure(View.java:8171) 09-18 17:47:52.869: E/AndroidRuntime(1122): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 09-18 17:47:52.869: E/AndroidRuntime(1122): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 09-18 17:47:52.869: E/AndroidRuntime(1122): at android.view.View.measure(View.java:8171) 09-18 17:47:52.869: E/AndroidRuntime(1122): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 09-18 17:47:52.869: E/AndroidRuntime(1122): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 09-18 17:47:52.869: E/AndroidRuntime(1122): at android.view.View.measure(View.java:8171) 09-18 17:47:52.869: E/AndroidRuntime(1122): at android.view.ViewRoot.performTraversals(ViewRoot.java:801) 09-18 17:47:52.869: E/AndroidRuntime(1122): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727) 09-18 17:47:52.869: E/AndroidRuntime(1122): at android.os.Handler.dispatchMessage(Handler.java:99) 09-18 17:47:52.869: E/AndroidRuntime(1122): at android.os.Looper.loop(Looper.java:123) 09-18 17:47:52.869: E/AndroidRuntime(1122): at android.app.ActivityThread.main(ActivityThread.java:4627) 09-18 17:47:52.869: E/AndroidRuntime(1122): at java.lang.reflect.Method.invokeNative(Native Method) 09-18 17:47:52.869: E/AndroidRuntime(1122): at java.lang.reflect.Method.invoke(Method.java:521) 09-18 17:47:52.869: E/AndroidRuntime(1122): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 09-18 17:47:52.869: E/AndroidRuntime(1122): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 09-18 17:47:52.869: E/AndroidRuntime(1122): at dalvik.system.NativeStart.main(Native Method)