我有这个布局文件和java代码。
我需要创建一个可水平滚动的线性布局来滚动按钮。 这样它根本不会滚动。
<ScrollView
android:id="@+id/questionListSV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fillViewport="true">
<LinearLayout
android:id="@+id/questionList_LL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
</LinearLayout>
</ScrollView>
for (int i =0; i<maxQuestionNo;i++) {
Button qbtn = new Button(mContext);
qbtn.setText(String.valueOf(i + 1));
ll.addView(qbtn);
}
答案 0 :(得分:2)
您需要使用HorizontalScrollView而不是ScrollView
<HorizontalScrollView
android:id="@+id/questionListSV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fillViewport="true">
<LinearLayout
android:id="@+id/questionList_LL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
</LinearLayout>
</HorizontalScrollView>