[英]How to overlap an image over an element inside a LinearLayout
我試圖在我的Android應用中創建一個教程,我想在某些UI元素上放一些氣球。 我的UI建立在LinearLayouts
。
如何將浮動圖像放置在LinearLayout
上的特定位置(即,帶有id =“ @ id / email”的文本字段旁邊)。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp" >
<TextView android:id="@+id/email"
style="@style/LoginBarText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="3.0dp"
android:text="Email:" />
</LinearLayout>
我知道唯一可以重疊元素的布局是RelativeLayout,但是它不能作用於其他布局中的元素。
謝謝
您可以創建一個RelativeLayout
並包含原始的LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include
layout="@layout/layout_original"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<include
layout="@layout/layout_overlay"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
或者,如果您只需要在元素旁邊(而不是頂部)添加圖片,請嘗試以下操作:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:orientation="horizontal">
<ImageView android:id="@+id/image"
android:src="@drawable/imagename"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="invisible" />
<TextView android:id="@+id/email"
style="@style/LoginBarText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="3.0dp"
android:text="Email:" />
</LinearLayout>
然后在活動調用中
image = (ImageView) findViewById(R.id.image);
image.setVisibility(View.VISIBLE);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.