当我更改布局的排列,并相应地更改依赖关系时,我得到一个例外。
我有以下布局(导致错误):
<LinearLayout
android:id="@+id/followerssLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tagsLayout">
<ImageView
android:id="@+id/imgFollowers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:scaleType="fitXY"
android:src="@drawable/ic_users"
android:contentDescription="@drawable/ic_users" />
<TextView
android:id="@+id/lblSelectedFollowers"
android:layout_width="0dp"
android:layout_height="wrap_content"
style="@style/LabelData"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:layout_weight=".75"
android:hint="@+string/select_followers" />
<ImageButton
android:id="@+id/imgbAddUsers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:scaleType="fitXY"
android:src="@drawable/ic_add_user"
android:contentDescription="@drawable/ic_add_user"
android:visibility="gone" />
</LinearLayout>
<LinearLayout
android:id="@+id/buttonsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/followerssLayout"
android:paddingBottom="15sp">
<Button
android:id="@+id/btnDeleteTask"
style="@style/Widget.Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/delete"
android:layout_weight=".5"
android:layout_marginLeft="5sp"
android:layout_marginStart="5sp"
android:layout_marginRight="5sp"
android:layout_marginEnd="5sp" />
<Button
android:id="@+id/btnSaveTask"
style="@style/Widget.Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/save"
android:layout_weight=".5"
android:layout_marginLeft="5sp"
android:layout_marginStart="5sp"
android:layout_marginRight="5sp"
android:layout_marginEnd="5sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/subTasksLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/buttonsLayout"
android:paddingBottom="15sp">
<ImageView
android:id="@+id/imgSubTasks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:scaleType="fitXY"
android:src="@drawable/ic_sub_tasks"
android:contentDescription="@drawable/ic_sub_tasks" />
<ListView
android:id="@+id/lstSubTasks"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".55">
</ListView>
<TextView
android:id="@+id/lblEmpty"
android:hint="@string/add_subtask"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_gravity="center_vertical"
android:visibility="gone"
style="@style/LabelData">
</TextView>
</LinearLayout>
这会导致以下异常:
05-18 18:29:35.897: E/AndroidRuntime(1508): FATAL EXCEPTION: main
05-18 18:29:35.897: E/AndroidRuntime(1508): java.lang.ClassCastException:
android.widget.Button cannot be cast to android.widget.ListView
05-18 18:29:35.897: E/AndroidRuntime(1508): at com.horizons.engiz.ui.FragManageTask.onCreateView(FragManageTask.java:142)
05-18 18:29:35.897: E/AndroidRuntime(1508): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1504)
05-18 18:29:35.897: E/AndroidRuntime(1508): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:942)
05-18 18:29:35.897: E/AndroidRuntime(1508): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1121)
05-18 18:29:35.897: E/AndroidRuntime(1508): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
05-18 18:29:35.897: E/AndroidRuntime(1508): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1484)
05-18 18:29:35.897: E/AndroidRuntime(1508): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:450)
05-18 18:29:35.897: E/AndroidRuntime(1508): at android.os.Handler.handleCallback(Handler.java:615)
05-18 18:29:35.897: E/AndroidRuntime(1508): at android.os.Handler.dispatchMessage(Handler.java:92)
05-18 18:29:35.897: E/AndroidRuntime(1508): at android.os.Looper.loop(Looper.java:137)
05-18 18:29:35.897: E/AndroidRuntime(1508): at android.app.ActivityThread.main(ActivityThread.java:4745)
05-18 18:29:35.897: E/AndroidRuntime(1508): at java.lang.reflect.Method.invokeNative(Native Method)
05-18 18:29:35.897: E/AndroidRuntime(1508): at java.lang.reflect.Method.invoke(Method.java:511)
05-18 18:29:35.897: E/AndroidRuntime(1508): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-18 18:29:35.897: E/AndroidRuntime(1508): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-18 18:29:35.897: E/AndroidRuntime(1508): at dalvik.system.NativeStart.main(Native Method)
重要信息:当我将buttons Layout
置于sub Tasks Layout
下方并相应更改layout_below
时,它可以正常使用
任何帮助都将非常受欢迎