[英]Android - RelativeLayout - position a checkbox on the center of an image
我剛接觸Android ...
我想知道如何在我的RelativeLayout視圖上將復選框居中放置在圖像上-沒有像這樣的屬性...
這是我的代碼: http : //pastebin.com/tGAxju3Z
請注意:圖片比復選框大...
謝謝你,丁。
對以下內容使用framelayout
<FrameLayout
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/image1"
>
<Button
android:id="@+id/button2"
android:layout_gravity="center"
android:src="@drawable/image2" />
</FrameLayout>
希望這可行...
如果您使用的是相對布局,則最好將LinearLayout的背景作為圖像,然后將復選框放置在linearlayout上。
確保CheckBox的layout_height與ImageView的layout_height相同,對於layout_width相同,並添加重力。 確保ImageView和Checkbox處於TextView以外的其他布局(layout_width和layout_height設置為wrap_content)。
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="5dp"
android:layout_gravity="center"
android:background="#e2e2e2"
>
<ImageView
android:contentDescription="Icon"
android:layout_width="74dp"
android:layout_height="64dp"
android:id="@+id/imgThumbnail"
android:scaleType="centerInside"
/>
<CheckBox
android:id="@+id/chkEdit"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:visibility="visible"
/>
</RelativeLayout>
<TextView />
提示:將android:background =“#FF0000”(= RED)和android:background =“#00FF00”(= GREEN)添加到不同的小部件中,這樣您就可以准確地看到該項目所涵蓋的內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.