在relativelayout中无法看到edittext(offscreen)

时间:2015-02-06 16:28:18

标签: android relativelayout

我有以下相对布局,其下面有一个带有EditText的列表视图。我无法看到编辑文本,因为列表占据了整个屏幕。

如何在不滚动的情况下同时在屏幕上同时显示listview和edittext?

我尝试了很多布局参数

感谢

<?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>

3 个答案:

答案 0 :(得分:1)

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

<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>

答案 1 :(得分:0)

更改EditText并将其对齐到底部。现在,你告诉它在列表下面,所以如果列表占据了整个高度,那么就没有空间了。

<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" >  //here
</EditText>

如果您希望它在列表下方(即使列表未填满整个屏幕),那么您可能想要使用addFooterView()

答案 2 :(得分:0)

尝试:

<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:gravity="bottom"
    android:layout_alignParentBottom="true" >
</EditText>