【发布时间】:2018-11-30 17:10:47
【问题描述】:
布局换行内容不起作用
下面是我的 XML 代码。我想将灰色部分线性布局放置在主图像上方。 Screenshot of my code here.
在宽高比为 16:9 的设备中设计是正确的,但在 18:9 和 18.5:9 中,灰色部分位于顶部。
主题文本和图标必须位于主图的左上角。
别管顶面。从底部开始,高度必须是图像的大小
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:background="@color/light_green"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/dark_green">
<LinearLayout
android:id="@+id/topLin"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/grey"
android:orientation="horizontal">
<TextView
android:id="@+id/nameTxt"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:ellipsize="end"
android:gravity="center|start"
android:maxLength="25"
android:singleLine="true"
android:text="Abin Stanly"
android:textColor="@color/white"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:adjustViewBounds="true"
android:src="@drawable/test" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@id/imageView"
android:layout_marginStart="20dp"
android:layout_marginTop="15dp">
<ImageView
android:id="@+id/icon"
android:layout_width="@dimen/icon_height"
android:layout_height="@dimen/icon_height"
android:layout_gravity="center"
android:src="@drawable/ic_love" />
<TextView
android:id="@+id/topicTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:gravity="center"
android:paddingEnd="10dp"
android:shadowColor="@color/grey"
android:shadowDx=".5"
android:shadowDy=".5"
android:shadowRadius="3.5"
android:text="Topic"
android:textColor="@color/white"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
【问题讨论】:
-
从线性布局中移除
android:gravity="center" -
您需要精简布局。而是使用
ContraintLayout、FrameLayout或RelativeLayout。然后你就可以使用android:layout_topOf="@id/parentLinear"developer.android.com/training/constraint-layout -
@KaranMer 移除所有重力。没用
-
你的imageview高度是wrapcontent,设置成match_parent。
-
@AbinStanly 您能否提供您需要的确切用户界面?
标签: android android-linearlayout android-relativelayout