我有以下线性布局,我将它设置为 HorizontalScrollView
文件 menu.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/menu"
android:orientation="vertical" android:background="#2f4f4f" android:layout_width="wrap_content" android:layout_height="fill_parent">
<ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="#2f4f4f" android:cacheColorHint="#2f4f4f" android:scrollbars="none">
</ListView>
</LinearLayout>
文件:scrollview.xml
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#00ffffff" android:padding="0px"
android:layout_margin="0px" android:fadingEdge="none" android:fadingEdgeLength="0px" android:scrollbars="none">
<LinearLayout android:id="@+id/top" android:layout_height="fill_parent" android:layout_width="fill_parent"
android:orientation="horizontal" android:background="#ffffffff" android:padding="0px" android:layout_margin="0px">
</LinearLayout>
</HorizontalScrollView>
我正在尝试以编程方式设置线性布局的宽度,但我得到 ClassCastException。(LinearLayout$LayputParams 无法转换为 FrameLayout$LayputParams)
LayoutInflater inflater = LayoutInflater.from(this);
scrollView = inflater.inflate(R.layout.scrollview_xml, null);
setContentView(scrollView);
View menu = inflater.inflate(R.layout.menu_xml, null);
scrollView.addView(menu);
scrollView.getChildAt(0).setLayoutParams(new ViewGroup.LayoutParams(100,100));
如何解决这个问题?