【发布时间】:2017-02-28 11:54:19
【问题描述】:
我有一个文本视图,我想将宽度更改为 match_parent,并将高度更改为 wrap_content。它嵌套在水平线性布局中。它是 3 个文本视图中的第 2 个,每个文本视图的权重为 1。运行此特定片段时,它将其他两个按钮设置为
previousButton.setVisibility(View.GONE);
nextButton.setVisibility(View.GONE);
文本视图
<TextView
android:id="@+id/home"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="HOME"
android:layout_weight="1"
android:background="@drawable/button_selector"
android:layout_marginLeft="10dp"
android:layout_marginBottom="10dp"
android:padding="10dp"
android:gravity="center"
android:textColor="#000000"
android:textStyle="bold"
android:onClick="home"
/>
我正在使用以下内容尝试更改片段中的布局:
homeButton.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
当我运行它时,我得到了错误:
java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
【问题讨论】:
-
错误比较明显。您不能将
ViewGroup转换为LinearLayout。所以我猜你的TextView的父布局是Linear?
标签: android layoutparams