[英]display button at the very bottom of the screen and right side
如何在屏幕底部和右側顯示圖像按鈕。 現在,我正在像這樣使用,但是按鈕沒有顯示在屏幕的最底部。
<ImageButton
android:id="@+id/ibdGoBack"
android:layout_width="42dp"
android:layout_height="42dp"
android:layout_gravity="right|bottom"
android:background="@drawable/back_button"
android:contentDescription="@string/backbutton" />
屏幕上只有一個textview。
如果容器視圖是LinearLayout
則它應該可以正常工作。 我希望它是RelativeLayout
,希望您嘗試一下。
<ImageButton
android:id="@+id/ibdGoBack"
android:layout_width="42dp"
android:layout_height="42dp"
android:layout_gravity="right|bottom"
android:background="@drawable/back_button"
android:contentDescription="@string/backbutton"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />
不確定哪個是viewgroup
的父viewgroup
imagebutton
,但是如果您使用relativelayout
作為其父(或根)並使用alignParentBottom="true"
和alignParentRight="true"
,它可能對您alignParentRight="true"
使用RelativeLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageButton
android:id="@+id/ibdGoBack"
android:layout_width="42dp"
android:layout_height="42dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="@drawable/back_button"
android:contentDescription="@string/backbutton" />
</RelativeLayout>
或像這樣的LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="bottom|right">
<ImageButton
android:id="@+id/ibdGoBack"
android:layout_width="42dp"
android:layout_height="42dp"
android:background="@drawable/back_button"
android:contentDescription="@string/backbutton" />
</LinearLayout>
檢查此布局
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="@drawable/ic_launcher" />
</RelativeLayout>`
對於底部和右側,請使用以下簡單代碼:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageButton
android:layout_width="42dp"
android:layout_height="42dp"
android:background="@drawable/back_button"
android:contentDescription="@string/backbutton"
android:layout_gravity="bottom|right"/>
</FrameLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.