i found this code for making my layout scrollable. But how can i do the same thing when my layout is horizontal?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"> //I change it here to horizontal but no result
<!-- Content here -->
</LinearLayout>
</ScrollView>
答案 0 :(得分:0)
try this:
//add view of linear_Pmains to Linnearlayout of your layout
HorizontalScrollView scollview = new HorizontalScrollView(this);
View v2 = null;
LinearLayout linear_pmains = new LinearLayout(this);
linear_pmains.setOrientation(LinearLayout.HORIZONTAL);
lsellerbooks.removeAllViews();
// Do ur functionality
scollview.addView(linear_pmains);
答案 1 :(得分:0)
如果你想以xml文件的方式(绝对更好!),这就是它的工作原理:
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/horizontalScrollView" >
<LinearLayout
android:id="@+id/somelayout"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
</LinearLayout>
</HorizontalScrollView>
您不需要使用&#34; LinearLayout&#34;但由于它是一个ScrollView,它只能容纳一个孩子。因此内部必须有某种布局。