Как разместить изображение в верхней части другого изображения в android
Это мой макет, который я пробовал до сих пор без успеха
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white">
<LinearLayout
android:id="@+id/lltest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_centerHorizontal="true">
<ImageView
android:id="@+id/inside_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
android:src="@drawable/frame"/>
</LinearLayout>
<ImageView
android:id="@+id/outside_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/inside_imageview"
android:scaleType="fitXY"/>
</RelativeLayout>
То, что я точно хочу, - это иметь внешний вид out_imageview поверх inner_imageview с точной высотой и шириной... Как это сделать с помощью макета?
Ответы
Ответ 1
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white" >
<ImageView
android:id="@+id/inside_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginTop="5dip"
android:src="@drawable/frame" />
<ImageView
android:id="@+id/outside_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/inside_imageview"
android:layout_alignBottom="@id/inside_imageview"
android:layout_alignLeft="@id/inside_imageview"
android:layout_alignRight="@id/inside_imageview"
android:scaleType="fitXY" />
</RelativeLayout>
Атрибут layout_align[Top|Bottom|Left|Right]
в RelativeLayout
используется для выравнивания представлений на основе их соответствующих значений x и y в пределах поля. Второй ImageView
теперь будет выровнен по верхней, нижней, левой и правой части первого ImageView
на основе полей. Прокладка игнорируется при выравнивании.
Ответ 2
FrameLayout
- это то, что вам нужно. Вы можете просто объединить родительский макет, который также является FrameLayout
.
Взгляните на Блог разработчиков Android: http://android-developers.blogspot.it/2009/03/android-layout-tricks-3-optimize-by.html
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center">
<ImageView
android:id="@+id/outside_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"/>
<ImageView
android:id="@+id/inside_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
android:src="@drawable/frame" />
</merge>
Ответ 3
Вы должны попробовать FrameLayout
. Внутри FrameLayout каждый Ребенок находится поверх друг друга.
Ответ 4
Вам нужен макет кадра. Попробуйте проверить AndroidFrameLayout
.
Ответ 5
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/_15dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/_10dp"
android:layout_marginTop="@dimen/_50dp"
android:background="@drawable/white_background"
/>
<ImageView
android:layout_width="@dimen/_100dp"
android:layout_height="@dimen/_100dp"
android:background="@drawable/my_credit"
android:layout_marginTop="@dimen/_5dp"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
Ответ 6
Я пробовал этот путь, и это сработало для меня, надеюсь, что это поможет
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dip">
<ImageView
android:id="@+id/image_first"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/imga"/>
<ImageView
android:id="@+id/imageview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/image"/>
</FrameLayout>