相对布局中ImageView后面的线性布局
Linear Layout behind ImageView in Relative Layout
让我解释一下我有一个像这样的 xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imgCircle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img_circle" />
<LinearLayout
android:id="@+id/llFirstScreen"
android:layout_alignTop="@id/imgCircle"
android:layout_alignBottom="@id/imgCircle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/imgCircle"
android:layout_toEndOf="@id/imgCircle"
android:background="@drawable/layout_view_round_corner"
android:orientation="vertical">
<TextView
android:id="@+id/mapCurrentLocation"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="TextView1"
android:textColor="@color/lblTextColor"
android:textSize="@dimen/lblTextLarge"
android:textStyle="normal" >
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="TextView2"
android:textColor="@color/lblHintColor2"
android:textSize="@dimen/lblTextMedium"
android:textStyle="normal" >
</TextView>
</LinearLayout>
</RelativeLayout>
这给了我旁边的 Image 和 TextViews
但我想完成这样的事情
TextView 背景在圆形图像的一半(在它后面)处被扩展(可能填充),因此它看起来像图像的 "part"。或者我正在考虑在 TextView 后面制作一个背景为白色的视图,以便它看起来那样。但是想在这里问问有没有更好的办法。
我希望我解释清楚了(这就是我添加图片的原因)。
我已尝试将演示与您的 xml 文件一起使用,您可以查看以下代码。我必须给出 ImageView
的静态高度和宽度才能获得结果。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/llFirstScreen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/imgCarCircle"
android:layout_alignTop="@id/imgCarCircle"
android:layout_marginLeft="30dp"
android:background="@color/colorAccent"
android:orientation="vertical"
android:paddingLeft="40dp">
<TextView
android:id="@+id/mapCurrentLocation"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="text1"
android:textStyle="normal"></TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="text2"
android:textStyle="normal"></TextView>
</LinearLayout>
<ImageView
android:id="@+id/imgCarCircle"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@mipmap/ic_launcher_round" />
</RelativeLayout>
试试这些:
第一个解决方案:改变这个
<LinearLayout
android:id="@+id/llFirstScreen"
android:layout_alignTop="@id/imgCircle"
android:layout_alignBottom="@id/imgCircle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/imgCircle"
android:layout_toEndOf="@id/imgCircle"
android:background="@drawable/layout_view_round_corner"
android:orientation="vertical">
对此:
<LinearLayout
android:id="@+id/llFirstScreen"
android:layout_alignTop="@id/imgCircle"
android:layout_alignBottom="@id/imgCircle"
android:layout_width="match_parent"
android:layout_marginLeft="20dp" // or just figure your image width and set this programatically
android:layout_height="wrap_content"
android:background="@drawable/layout_view_round_corner"
android:orientation="vertical">
第二种解决方案:使用AbsoluteLayout有点难处理。
让我解释一下我有一个像这样的 xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imgCircle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img_circle" />
<LinearLayout
android:id="@+id/llFirstScreen"
android:layout_alignTop="@id/imgCircle"
android:layout_alignBottom="@id/imgCircle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/imgCircle"
android:layout_toEndOf="@id/imgCircle"
android:background="@drawable/layout_view_round_corner"
android:orientation="vertical">
<TextView
android:id="@+id/mapCurrentLocation"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="TextView1"
android:textColor="@color/lblTextColor"
android:textSize="@dimen/lblTextLarge"
android:textStyle="normal" >
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="TextView2"
android:textColor="@color/lblHintColor2"
android:textSize="@dimen/lblTextMedium"
android:textStyle="normal" >
</TextView>
</LinearLayout>
</RelativeLayout>
这给了我旁边的 Image 和 TextViews
但我想完成这样的事情
TextView 背景在圆形图像的一半(在它后面)处被扩展(可能填充),因此它看起来像图像的 "part"。或者我正在考虑在 TextView 后面制作一个背景为白色的视图,以便它看起来那样。但是想在这里问问有没有更好的办法。
我希望我解释清楚了(这就是我添加图片的原因)。
我已尝试将演示与您的 xml 文件一起使用,您可以查看以下代码。我必须给出 ImageView
的静态高度和宽度才能获得结果。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/llFirstScreen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/imgCarCircle"
android:layout_alignTop="@id/imgCarCircle"
android:layout_marginLeft="30dp"
android:background="@color/colorAccent"
android:orientation="vertical"
android:paddingLeft="40dp">
<TextView
android:id="@+id/mapCurrentLocation"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="text1"
android:textStyle="normal"></TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="text2"
android:textStyle="normal"></TextView>
</LinearLayout>
<ImageView
android:id="@+id/imgCarCircle"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@mipmap/ic_launcher_round" />
</RelativeLayout>
试试这些: 第一个解决方案:改变这个
<LinearLayout
android:id="@+id/llFirstScreen"
android:layout_alignTop="@id/imgCircle"
android:layout_alignBottom="@id/imgCircle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/imgCircle"
android:layout_toEndOf="@id/imgCircle"
android:background="@drawable/layout_view_round_corner"
android:orientation="vertical">
对此:
<LinearLayout
android:id="@+id/llFirstScreen"
android:layout_alignTop="@id/imgCircle"
android:layout_alignBottom="@id/imgCircle"
android:layout_width="match_parent"
android:layout_marginLeft="20dp" // or just figure your image width and set this programatically
android:layout_height="wrap_content"
android:background="@drawable/layout_view_round_corner"
android:orientation="vertical">
第二种解决方案:使用AbsoluteLayout有点难处理。