【问题标题】:Layout on the bottom of Relative layout overlays the views under it相对布局底部的布局覆盖了它下面的视图
【发布时间】:2014-09-23 13:12:09
【问题描述】:

我的屏幕由四个主要视图组成:

1)admob 视图

2)顶部布局

3)ScrollView居中,以编程方式填充

4) 底视图。 EditView 的高度可以在那里展开。

问题是底视图覆盖了滚动视图的内容。 也就是说scrollView不会在底部布局的开头结束。

网站禁止我发太多代码,所以我发短xml。

<?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"
            android:orientation="vertical"
    >
<include layout="@layout/adview"
         android:layout_alignParentTop="true"
        />

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/top"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:gravity="center_horizontal|center_vertical"
              android:orientation="horizontal"
              android:layout_below="@+id/adView"
        >
        <TextView
                android:id="@+id/textChatSubjectTitle"
                android:text='Subject'
                android:layout_width="wrap_content"
                android:layout_weight="5"
                android:layout_height="wrap_content"
                />
    <ImageView
            android:id="@+id/imageChatImageTitle"
            android:layout_height="fill_parent"
            android:layout_width="wrap_content"
            />
</LinearLayout>


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/scrollChat"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@color/backNormal"
            android:orientation="vertical"
            android:layout_below="@+id/top"
        >
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:id="@+id/linearChat"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:orientation="vertical"
            >
    </LinearLayout>
</ScrollView>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="horizontal"
              android:layout_alignParentBottom="true"
        >
    <ImageView
            android:id="@+id/buttonClip"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_gravity= "center_vertical|center_horizontal"
            />


    <EditText
            android:id="@+id/editChatMessage"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:inputType="textMultiLine|textCapSentences"
            android:minLines="1"
            android:gravity="top|left"
            android:maxLines="5"
            android:maxLength="500"
            android:layout_marginRight="5dp"
            android:layout_weight="5"
            android:scrollHorizontally="false"
            />
    <Button
            android:id="@+id/buttonChatSend"
            android:text='send'
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/darkGray"
            />
</LinearLayout>
</RelativeLayout>

有什么想法吗? 谢谢!

【问题讨论】:

    标签: android android-layout android-edittext android-relativelayout


    【解决方案1】:

    试试这个。我给了你的底部面板一个 id,然后在你的 ScrollView 中添加了一个 android:layout_above 标签。我还根据收到的 lint 警告进行了清理:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <include layout="@layout/adview" 
            android:layout_width="match_parent" 
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"/>
    
        <LinearLayout
            android:id="@+id/top"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/adView"
            android:gravity="center_horizontal|center_vertical"
            android:orientation="horizontal">
    
            <TextView
                android:id="@+id/textChatSubjectTitle"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="5"
                android:text="Subject"/>
    
            <ImageView
                android:id="@+id/imageChatImageTitle"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"/>
        </LinearLayout>
    
        <ScrollView
            android:id="@+id/scrollChat"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/bottomPanel"
            android:layout_below="@+id/top"
            android:background="@color/backNormal"
            android:orientation="vertical">
    
            <LinearLayout
                android:id="@+id/linearChat"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
            </LinearLayout>
        </ScrollView>
    
        <LinearLayout android:id="@+id/bottomPanel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:orientation="horizontal">
    
            <ImageView
                android:id="@+id/buttonClip"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical|center_horizontal"
                android:layout_weight="1"/>
    
            <EditText
                android:id="@+id/editChatMessage"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dp"
                android:layout_weight="5"
                android:gravity="top|left"
                android:inputType="textMultiLine|textCapSentences"
                android:maxLength="500"
                android:maxLines="5"
                android:minLines="1"
                android:scrollHorizontally="false"/>
    
            <Button
                android:id="@+id/buttonChatSend"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="send"
                android:textColor="@color/darkGray"/>
        </LinearLayout>
    
    </RelativeLayout>
    

    【讨论】:

    • 是的!非常感谢!但我不明白你做了什么:我还根据收到的 lint 警告清理了一些东西:
    猜你喜欢
    • 1970-01-01
    • 2011-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多