【问题标题】:Linear Layout overlapping with Scroll view and other Linear Layout与滚动视图和其他线性布局重叠的线性布局
【发布时间】:2019-02-09 18:20:58
【问题描述】:

最近遇到一个问题。我的编辑文本和图像按钮所在的线性布局与我的工具栏和滚动视图重叠。我已经尝试过其他的东西,比如 layout_below 等,但没有任何效果。群聊.xml

<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="match_parent"
tools:context=".GroupChatActivity"
android:orientation="vertical">

<include
    android:id="@+id/group_chat_bar_layout"
    layout="@layout/app_bar_layout">
</include>

<ScrollView
    android:id="@+id/my_scroll_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/group_chat_bar_layout"
    android:layout_above="@+id/myLinearLayout">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            android:id="@+id/group_chat_text_display"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:textAllCaps="false"
            android:textSize="20sp"
            android:textColor="@android:color/background_dark"
            android:layout_marginStart="2dp"
            android:layout_marginEnd="2dp"
            android:layout_marginBottom="50dp"/>

    </LinearLayout>
</ScrollView>

<LinearLayout
    android:id="@+id/myLinearLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <EditText
        android:id="@+id/input_group_message"
        android:layout_width="270dp"
        android:layout_height="wrap_content"
        android:hint="Write message..." />

    <ImageButton
        android:id="@+id/send_message_button"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:src="@drawable/send_message" />

</LinearLayout>

这是 groupchat.xml 文件在 Android Studio 中的预览效果: enter image description here

这就是应用在这段代码中的样子。 This are the results

以防万一,这是我工具栏的代码:Appbarlayout.xml

<android.support.v7.widget.Toolbar
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:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

它在一个单独的 xml 中,因为我将它用于我的应用程序中的其他活动,这就是为什么在 th Groupchat.xml 中包含 ang

我也在关注这个 TUTORILA。我建议你去那里看看,因为那是我关注的。

go to this video

谢谢。

【问题讨论】:

    标签: android scrollview android-linearlayout toolbar


    【解决方案1】:

    问题在于布局位置。您的带有 ID 的 LinearLayout:myLinearLayout 未在 RelativeLayout 中的任何位置对齐,这就是它在屏幕顶部呈现的原因。进行以下更改,一切顺利。

    在您的具有 id:myLinearLayout 的 LinearLayout 中,添加以下行:

    android:layout_alignParentBottom="true"
    

    像这样:

    <LinearLayout
        android:id="@+id/myLinearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal">
    

    【讨论】:

      【解决方案2】:

      添加

       android:layout_below="@+id/group_chat_bar_layout"
      

      这条线到LinearLayout

      <LinearLayout
          android:id="@+id/myLinearLayout"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_below="@+id/group_chat_bar_layout"
          android:orientation="horizontal">
      
          <EditText
              android:id="@+id/input_group_message"
              android:layout_width="270dp"
              android:layout_height="wrap_content"
              android:hint="Write message..." />
      
          <ImageButton
              android:id="@+id/send_message_button"
              android:layout_width="50dp"
              android:layout_height="wrap_content"
              android:src="@drawable/bkg" />
      
      </LinearLayout>`
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-02
        • 1970-01-01
        • 2012-04-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多