【问题标题】:list view inside relative layout not taking entire screen height相对布局内的列表视图不占用整个屏幕高度
【发布时间】:2015-03-23 10:14:04
【问题描述】:

代码没有全屏显示...
列表视图的大小不适合整个屏幕。

<RelativeLayout
    android:id="@+id/linearlayoutassigt"
    android:layout_width="250dp"
    android:layout_height="340dp" >

    <ListView
        android:id="@+id/listviewassignments"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="13dp"
        android:background="@drawable/round_bottom"
        android:divider="@android:color/darker_gray"
        android:dividerHeight="0.5dp"
        android:listSelector="#00000000"
        android:padding="10dp"
        android:scrollbarStyle="outsideOverlay"
        >
    </ListView>

    <TextView
        android:id="@+id/emptyText"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:layout_gravity="center_vertical|center_horizontal"
        android:gravity="center_horizontal"
        android:text="@string/ID_NO_ASSIGNMENT_MSG"
        android:textColor="@android:color/black"
        android:visibility="gone" />

    <ProgressBar
        android:id="@+id/progressbarassignmentload"
        style="@android:style/Widget.ProgressBar.Small"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_gravity="center_horizontal|center_vertical" />

    <TextView
        android:id="@+id/student_left_frag_assignment_error_text"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:paddingLeft="10dp"
        android:textColor="@android:color/black" />
</RelativeLayout>

【问题讨论】:

  • ListView 的父级在您的情况下是 RelativeLayout,其高度设置为 android:layout_width="250dp"。所以列表视图的最大高度是250dp。将其更改为 match_parent
  • 还有一个这样的问题,你被标记为垃圾邮件朋友。珍惜别人的时间,不要重复同一行文字,因为你对某些事情没有成功感到沮丧。
  • @hrskrs 我在任何时候都同意你的观点
  • 在相对布局的宽度和高度中使用 match_parent 并从列表视图中删除填充。

标签: android android-layout


【解决方案1】:

您已经对根布局进行了硬编码。请使其与父级匹配。

<RelativeLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content">

【讨论】:

    【解决方案2】:

    只需更新您的父布局。

     <RelativeLayout
              android:id="@+id/linearlayoutassigt"
              android:layout_width="match_parent"
              android:layout_height="match_parent" >
    

    ================================================ 试试这个方法。。

     <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
    
    
            <ListView
                android:id="@+id/listviewassignments"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:divider="@android:color/darker_gray"
                android:dividerHeight="1dp"
                android:listSelector="#00000000"
                android:scrollbars="vertical"
                android:smoothScrollbar="true"
                android:scrollbarStyle="outsideOverlay"
                >
            </ListView>
    
            <TextView
                android:id="@+id/emptyText"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_centerInParent="true"
                android:layout_gravity="center_vertical|center_horizontal"
                android:gravity="center_horizontal"
                android:text="@string/app_name"
                android:textColor="@android:color/black"
                android:visibility="gone" />
    
            <ProgressBar
                android:id="@+id/progressbarassignmentload"
                style="@android:style/Widget.ProgressBar.Small"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_gravity="center_horizontal|center_vertical" />
    
            <TextView
                android:id="@+id/student_left_frag_assignment_error_text"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:paddingLeft="10dp"
                android:textColor="@android:color/black" />
    
    
    </LinearLayout>
    

    如果不行,请告诉我

    【讨论】:

      【解决方案3】:

      这个 xml 编码不好。发布图片说明设计的外观。

      TextView 是 ma​​tch_parent,因此由于 z-ordering,您会看到 textView 仅更改为 wrap_content。也没有亲戚关系!!!

      【讨论】:

        【解决方案4】:

        改变

        <RelativeLayout
            android:id="@+id/linearlayoutassigt"
            android:layout_width="250dp"
            android:layout_height="340dp" />
        

        <RelativeLayout
            android:id="@+id/linearlayoutassigt"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2023-03-11
          • 2019-08-05
          • 1970-01-01
          • 2019-09-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多