这里我在我的线性布局中使用 ScrollView 。但是我想在我的 ScrollView 线性布局中包含另一个 ListView 。
Scrollview 只支持一个子项。我知道在 scrollview 里面 listview 不工作。但是有没有其他选项可以使用 listview。我想滚动所有内容。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="@+id/widget54"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<LinearLayout
android:layout_width="310px"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 1"
/>
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 2"
/>
<Button
android:id="@+id/button3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 3"
/>
<EditText
android:id="@+id/txt"
android:layout_width="fill_parent"
android:layout_height="300px"
/>
<Button
android:id="@+id/button4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 4"
/>
</LinearLayout>
</ScrollView>
最佳答案
ScrollView 中的 ListView 肯定无法正常工作。
我能想到的唯一方法是在界面中只有一个 ListView ,并为其创建一个自定义适配器:
public class HeaderAdapter{
private Adapter mAdapter; // this adapter is the adapter that you will normally have, for your listview
getViewTypeCount(){
return mAdapter.getViewTypeCount() + 1;
}
getView(int pos, View convertView){
// Handle only the first position, othervise, let mAdapter return
if (pos!=0) return mAdapter.getView(pos-1, convertView);
//
View v = LayoutInflater.inflate(R.layout.other_linear_layout);
// Bind the v if necessary
return v;
}
}
以上只是一个示例,您的想法是将其余内容(线性布局、按钮、编辑文本等)视为适配器的“标题”行。
关于android - android中linearlayout中scrollview listview如何解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10943526/