2017-09-05 75 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> 

這是奉承(我你擺脫了額外的嵌套佈局)。因此,更高性能