2017-09-05 79 views
-2

我希望ExpandableListView填满屏幕,我想要在ExpandableListView以下的内部RelativeLayout,但ExpandableListView将填满整个屏幕,我看不到RelativeLayout如何将TextView放在ExpandableListView下并使ExpandableListView填充剩余空间屏幕?

我在做什么错?

我有这样的布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:paddingTop="@dimen/all_pages_padding_top" 
    tools:context="driver.mci.ir.mcicardriver.activity.MessagesActivity"> 

    <ExpandableListView 
     android:id="@+id/messagesListView" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent" 
     android:background="@color/colorBackground" 
     android:layout_gravity="right|top"> 
    </ExpandableListView> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_below="@+id/messagesListView" 
     android:layout_alignParentBottom="true" 
     android:orientation="horizontal"> 

     <ImageButton 
      android:id="@id/imageView3" 
      android:layout_width="@dimen/login_icon_size" 
      android:layout_height="@dimen/login_icon_size" 
      android:scaleType="fitXY" 
      android:src="@drawable/sendmessage" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentTop="true" 
      /> 
     <EditText 
      android:id="@+id/userName" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignBottom="@+id/imageView3" 
      android:layout_toStartOf="@+id/imageView3" /> 

    </RelativeLayout> 
</RelativeLayout> 
+1

如果使用'scrollView'会怎么样? –

+0

我不想滚动任何东西。它不应该 –

+0

您是否想要可扩展列表视图应该是第一个元素,并且包含图像按钮和文本的第二个相对布局应该在第二个孩子的底部? @MahboobehMohammadi – Ankita

回答

0

试试这个,

删除**在布局我只是用突出的线条

相当不知道任何人都可以编辑这条评论,以改善:

您将ExpandableListView的高度设置为android:layout_height =“match_parent”,并且在尝试将属性设置为下面的布局之后,它已经采用全高。但在这里我给底部布局必须是相对布局的ExpandableListView具有前来以上相对布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" 
android:paddingTop="@dimen/all_pages_padding_top" 
tools:context="driver.mci.ir.mcicardriver.activity.MessagesActivity"> 

<ExpandableListView 
    android:id="@+id/messagesListView" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:background="@color/colorBackground" 
    **android:layout_above="@+id/textLayout"** 
    android:layout_gravity="right|top"> 
</ExpandableListView> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    **android:id="@+id/textLayout"** 
    android:layout_alignParentBottom="true" 
    android:orientation="horizontal"> 

    <ImageButton 
     android:id="@id/imageView3" 
     android:layout_width="@dimen/login_icon_size" 
     android:layout_height="@dimen/login_icon_size" 
     android:scaleType="fitXY" 
     android:src="@drawable/sendmessage" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentTop="true" 
     /> 
    <EditText 
     android:id="@+id/userName" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/imageView3" 
     android:layout_toStartOf="@+id/imageView3" /> 

</RelativeLayout> 
+0

它的工作原理,谢谢。但我不明白它使用'android:layout_above'和'android:layout_below'之间的区别? –

+0

@MahboobehMohammadi我已经更新了答案,你可以检查 – Raghavendra

+1

'使用android:layout_above和android:layout_below?'上面* *之间的差异意味着* *之上的*(所以,*之前*,垂直方向)之间的差异。 *下面*是相反的(所以,*下*)。 –

1

试试这个优化布局:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:paddingTop="@dimen/all_pages_padding_top" 
    tools:context="driver.mci.ir.mcicardriver.activity.MessagesActivity" 
    > 
    <ImageButton 
     android:id="@id/imageView3" 
     android:layout_width="@dimen/login_icon_size" 
     android:layout_height="@dimen/login_icon_size" 
     android:layout_alignParentBottom="true" 
     android:scaleType="fitXY" 
     android:src="@drawable/sendmessage" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentTop="true" 
    /> 
    <EditText 
     android:id="@+id/userName" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@id/imageView3" 
     android:layout_toStartOf="@+id/imageView3" 
    /> 
    <ExpandableListView 
     android:id="@+id/imageView3" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent" 
     android:layout_above="@id/messagesListView" 
     android:background="@color/colorBackground" 
     android:layout_gravity="right|top" 
    /> 
</RelativeLayout> 

这是奉承(我你摆脱了额外的嵌套布局)。因此,更高性能