我想在列表视图的末尾添加一个按钮。我有以下xml文件。“列表”视图显示其内容,但该按钮未显示。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/myListView" />
<Button
android:text="Project Download"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/download" />
</LinearLayout>
发布于 2015-09-16 11:40:49
问题在于android:layout_height="match_parent"
属性在您的ListView中。match_parent
意味着列表视图将填充所有的空格。正确的方法是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:weight="1"
android:id="@+id/myListView" />
<Button
android:text="Project Download"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/download" />
</LinearLayout>
发布于 2015-09-16 13:00:56
您的按钮没有显示,因为您的ListView占用了整个空间,在将其layout_height设置为match_parent时隐藏了您的按钮。match_parent将占用整个可用空间。因此,将其改为wrap_content,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_parent"
android:id="@+id/myListView" />
<Button
android:text="Project Download"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/download" />
</LinearLayout>
wrap_content将您的视图包装到最小可用的高度/宽度,而不会隐藏任何东西或使任何事情不清楚。
发布于 2017-08-07 06:21:48
我也有同样的问题,并且解决了。您只需要将该布局包装到ScrollView中即可。
<ScrollView 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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_transaction_history"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</android.support.v7.widget.RecyclerView>
<Button
android:id="@+id/btn_history_load_more"
style="?borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:paddingBottom="@dimen/margin_big"
android:paddingTop="@dimen/margin_large"
android:text="@string/text_btn_load_more"
android:textColor="#009CDE"
android:textSize="@dimen/text_size_medium" />
</LinearLayout>
</ScrollView>
https://stackoverflow.com/questions/32617180
复制