如何才能拥有这种布局方式:
包含2个元素的相对布局:图标位于左侧,文本视图居中于父级。问题是,当文本变大时,它会覆盖图像,因为它的宽度是"wrap_content“。
如何解决这个问题?
发布于 2018-07-17 22:31:44
如果你知道图标的宽度,你总是可以这样做:
<?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="wrap_content">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@android:color/black"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:gravity="center"
android:text="Loremem ipsum Lorem ipsum Lorem ipsum"/>
发布于 2018-07-17 22:31:51
我从你的解释中理解到的是,你需要这样的东西
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:src="@mipmap/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_toRightOf="@+id/image"
android:layout_centerVertical="true"
android:gravity="center">
<TextView
android:id="@+id/tvMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="the quick brown fox jump over the lazy dog" />
</LinearLayout></RelativeLayout>
如果这不是你想要的,那么请发布你的代码来帮助理解这个问题
https://stackoverflow.com/questions/51383758
复制相似问题