Android 为什么我的ListView不能滚动?
请参阅下面的代码 我有一个片段,它在代码中将带有单个ListView“lstv”的布局膨胀为LinearLayout容器“llytFragmentContainer”。我遇到的问题是ListView无法滚动。我知道这可能与布局的设置有关 在碎片中充气布局的代码:Android 为什么我的ListView不能滚动?,android,android-layout,android-listview,Android,Android Layout,Android Listview,请参阅下面的代码 我有一个片段,它在代码中将带有单个ListView“lstv”的布局膨胀为LinearLayout容器“llytFragmentContainer”。我遇到的问题是ListView无法滚动。我知道这可能与布局的设置有关 在碎片中充气布局的代码: public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate th
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.frag, container, false);
}
片段布局:
<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/lstv"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
活动布局:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10"
android:padding="10dp"
android:orientation="horizontal"
android:weightSum="100" >
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="88"
style="@android:style/Widget.ProgressBar.Horizontal" />
<TextView
android:id="@+id/txtProgress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="12"
android:layout_marginLeft="10dp" />
</LinearLayout>
<TextView
android:id="@+id/txtCounter"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8"
android:gravity="center_horizontal"
android:textSize="20dp" />
<LinearLayout
android:id="@+id/llytFragmentContainer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="67">
</LinearLayout>
<Button
android:id="@+id/btnEnd"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="15"
android:text="End Tour" />
</LinearLayout>
您的listview中有多少内容?是的,并尝试传递android:height以匹配父对象(对于listview)我有足够的内容,其中listview被llytFragmentContainer下面的按钮“btnEnd”切断。我也尝试过让listview与父对象匹配,但似乎不起作用。不过,我发现了问题所在。显然,在代码中,我做了一个listview.setEnable(false)来防止用户通过单击来检查框。这也阻止了整个listview被拖动。