gpt4 book ai didi

Android - ImageView 覆盖另一个 ImageView

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:57:47 26 4
gpt4 key购买 nike

我想像这样制作一个 ImageView 覆盖另一个 ImageView;只有一半的绿色圆圈覆盖了图像:

enter image description here

我试过使用 RelativeLayout 并将两个 ImageView 都放在里面。然后我使用 android:layout_alignBottom 将圆圈覆盖在图像上。它确实覆盖了,但我不知道如何设置偏移量,以便只有一半的圆覆盖基本图像。

编辑:

对不起,这是我的布局xml代码

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="32sp" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_person_black"
android:adjustViewBounds="true"
android:id="@+id/image_view_product" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/image_view_product"
android:layout_centerHorizontal="true"
android:background="@drawable/image_view_circle"
android:src="@drawable/ic_circle" />

</RelativeLayout>

最佳答案

这个答案得到了很多赞成票。所以我尝试改进这个答案。与其他两个相比,这可能是更好的方法,因为此解决方案不需要固定布局或将屏幕等分,所以这样做可能更好。

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

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

<LinearLayout
android:id="@+id/viewA"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:orientation="horizontal">

<TextView
android:id="@+id/subject"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="Thi"
android:textColor="@android:color/white"
android:textSize="17sp"
/>

</LinearLayout>

<LinearLayout
android:id="@+id/viewB"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="horizontal">

<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="Thi"
android:textColor="@android:color/black"
android:textSize="17sp"
/>
</LinearLayout>

</LinearLayout>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:src="@drawable/plus"
app:layout_anchor="@+id/viewA"
app:layout_anchorGravity="bottom|right|end"/>

</android.support.design.widget.CoordinatorLayout>

替代方法试试这个

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

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

// this is your first layout to put the big image
// use src or backgroud image as per requirement

<LinearLayout
android:background="@color/red_error"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">

</LinearLayout>

// this is your bottom layout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">

</LinearLayout>
</LinearLayout>

// This is the imageview which overlay the first LinearLayout
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/success"
android:adjustViewBounds="true"
android:layout_gravity="center"/>
</FrameLayout>

它看起来像这样

enter image description here

为此找到了另一种解决方案(编辑)如果你的大图像尺寸是固定高度你可以试试这个

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<RelativeLayout
android:id="@+id/layoutTop"
android:background="@color/red_error"
android:layout_width="match_parent"
android:layout_height="200dp" >
</RelativeLayout>

<RelativeLayout
android:id="@+id/layoutBottom"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentBottom="true"
android:layout_below="@id/layoutTop" >
</RelativeLayout>

<ImageView
android:id="@+id/overlapImage"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_above="@id/layoutBottom"
android:layout_centerHorizontal="true"
android:layout_marginBottom="-20dp"
android:adjustViewBounds="true"
android:src="@drawable/testimage" />

</RelativeLayout>

引用:- Android: Placing ImageView on overlap between layouts

希望这会有所帮助。祝你好运

关于Android - ImageView 覆盖另一个 ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33864422/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com