如何在ExpandableListView下放置TextView并使ExpandableListView填充剩余的空间屏幕?

时间:2017-09-05 06:27:33

标签: android android-layout

我希望ExpandableListView填满屏幕,我想要RelativeLayout下面的内部ExpandableListView,但ExpandableListView将填满整个屏幕,我可以& #39;请参阅RelativeLayout

我做错了什么?

我有这个布局

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

2 个答案:

答案 0 :(得分: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>

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

答案 1 :(得分:0)

试试这个,

删除我刚用于突出显示行的布局中的**

还不确定是否有人可以编辑此评论以改进:

您将ExpandableListView的高度设为android:layout_height =&#34; match_parent&#34;并且在你试图放置一个带有属性的布局之后,它已经占据了整个高度。但是在这里我给出了底部布局必须是相对布局,ExpandableListView必须高于相对布局

val intent = Intent(context, MyActivity::class.java)                
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK