想请问一下,这个图片和布局为什么总是在外面呀?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context=".MainActivity">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_marginTop="180dp"
        android:padding="10dp">
        <ImageView
            android:id="@+id/imageView"
            android:layout_width="20dp"
            android:background="@drawable/p"
            android:layout_height="wrap_content"
            android:layout_weight="0.5" />
        <LinearLayout
            android:orientation="vertical"
            android:layout_marginLeft="23dp"
            android:layout_width="8dp"
            android:layout_height="match_parent"
            android:layout_weight="4">

            <TextView
                android:id="@+id/title"
                android:layout_width="239dp"
                android:layout_height="wrap_content"
                android:layout_weight="2.5"
                android:gravity="center_vertical"
                android:text="张三"
                android:textColor="#000000"
                android:textSize="18dp" />

            <TextView
                android:id="@+id/content"
                android:layout_width="214dp"
                android:layout_height="wrap_content"
                android:layout_weight="1.5"
                android:gravity="center_vertical"
                android:singleLine="true"
                android:text="粗体字码创建了一个布局页面"
                android:textColor="#A8A8A8"
                android:textSize="18dp" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:paddingRight="-50dp"
            android:layout_weight="1"
            android:gravity="right"
            android:orientation="vertical">

            <TextView
                android:id="@+id/time"
                android:layout_width="130dp"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:layout_marginRight="1dp"
                android:layout_weight="0.5"
                android:text="上午10点29"
                android:textColor="#A8A8A8"
                android:textSize="15dp" />

            <ImageView
                android:id="@+id/code"
                android:layout_width="130dp"
                android:layout_height="12dp"
                android:layout_gravity="right"
                android:layout_weight="0.5"
                android:background="@drawable/lin" />
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="277dp"
        android:layout_height="130dp"/>
    <ImageView
      
        android:layout_width="20dp"
        android:background="@drawable/o"
        android:layout_height="wrap_content"
        android:layout_weight="0.5" />
    
</LinearLayout>

太大了吧,将宽度设小一点

前面几个控件设置权重和宽度过多,导致最后的图片控件虽然有0.5的权重,但是界面上已经没有空间去给它显示了。

你这个布局可以优化LinearLayout,最外面两层都是horizontal那就没必要多嵌套一层。

两边布局可以固定宽度不设置权重,然后中间文字父LinearLayout宽度设为0,权重为1。这样省事很多