按钮没有出现在屏幕上

时间:2014-03-11 13:41:54

标签: android android-listview

我创建了一个应用程序,其中我显示带有图像和文本的列表视图。我在页面末尾添加了Button。但这并没有在屏幕上显示。我是android的新手。我怎么能解决这个问题?

这是我的UI XML代码:

<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:padding="8dp"
tools:context=".MainActivity" 
android:background="@drawable/maps">

<TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="@string/WAYLF"
  android:gravity="center"
  android:textSize="22sp" />

<ListView
    android:id="@+id/list_view"
    android:dividerHeight="4dp"
    android:cacheColorHint="@android:color/transparent"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<Button
 android:layout_width="match_parent"
 android:layout_height="35dp"
 android:text="@string/NEXT"
 android:background="@android:color/holo_green_light"
 android:layout_marginTop="25dp" />

2 个答案:

答案 0 :(得分:1)

android:layout_height="0dip"android:layout_weight="1"设置为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:background="@drawable/maps"
    android:orientation="vertical"
    android:padding="8dp"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/WAYLF"
        android:textSize="22sp" />

    <ListView
        android:id="@+id/list_view"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:cacheColorHint="@android:color/transparent"
        android:dividerHeight="4dp" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:layout_marginTop="25dp"
        android:background="@android:color/holo_green_light"
        android:text="@string/NEXT" />

</LinearLayout>

答案 1 :(得分:0)

输入RelativeLayout parrent然后设置一个静态marginBottom,它等于listview按钮的高度,之后将按钮放在parrent的底部

相关问题