android - 在相对布局中看不到编辑文本(屏幕外)

标签 android android-relativelayout

我有以下相对布局,其中有一个 ListView ,下面有一个 EditText。我看不到编辑文本,因为列表占据了整个屏幕。

如何在不滚动的情况下同时在屏幕上显示 ListView 和编辑文本?

我已经尝试了很多布局参数

谢谢

<?xml version="1.0" encoding="UTF-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
      >

    <TextView
        android:id="@+id/textviewassessments"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:background="@color/blue_alpha_background"
        android:textColor="#FFFFFF"
        android:text="Assessments" />

<ListView
        android:id="@+id/assessmentslist"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="15dp"
        android:background="#8fff"
        android:cacheColorHint="#0000"
        android:padding="5dp"
        android:divider="#FFCC00"
        android:dividerHeight="4px"
        android:layout_below="@id/textviewassessments" >
    </ListView>

<EditText
        android:id="@+id/editTextassessments"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="1"
        android:lines="7"
        android:inputType="textMultiLine"
        android:hint="Please type any comments..."
        android:layout_below="@id/assessmentslist" >
        </EditText>

</RelativeLayout>

最佳答案

如果你想使用 RelativeLayout 那么你应该把一个元素放在底部,另一个放在上面。 sample (未测试)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<EditText
        android:id="@+id/editTextassessments"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="1"
        android:lines="7"
        android:inputType="textMultiLine"
        android:hint="Please type any comments..."
        android:layout_alignParentBottom="true"   /> <!-- this will put the element on the bottom of the screen -->



<TextView
    android:id="@+id/textviewassessments"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:background="@color/blue_alpha_background"
    android:textColor="#FFFFFF"
    android:text="Assessments"
    android:layout_alignParentTop="true" 
  /> <!-- this will align the element to the head --> 

<ListView
        android:id="@+id/assessmentslist"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="15dp"
        android:background="#8fff"
        android:cacheColorHint="#0000"
        android:padding="5dp"
        android:divider="#FFCC00"
        android:dividerHeight="4px"
        android:layout_below="@id/textviewassessments"
        android:layout_above="@id/editTextassessments"
       /> <!-- this will put the the list between the both elements and stretch its size due match parent --> 


</RelativeLayout>

关于android - 在相对布局中看不到编辑文本(屏幕外),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28370320/

相关文章:

android - SQLite Android无法打开数据库文件

android - 动态更改 SDK 构建选项

android - 相对布局中的 ImageView 可见性问题

android - fill_parent 不适用于 ScrollView 中的 RelativeLayout

android - 在android中以其他用户身份登录时编辑解析用户信息

android - 从右到左添加android gridview项目

java - 无法解析 setLatestEventInfo 方法

android - 带有和不带有 "+"的 Android 布局 XML 中的 ID

android - SetMargin 在 RelativeLayout 中不起作用

android - 以编程方式生成的表格与父宽度不匹配