[英]putting button in top left corner of screen
我是Android Studios的新手,很抱歉,如果這是一個愚蠢的問題。 我試圖在屏幕頂部放置兩個按鈕。 我希望它們位於此圖像的左上角和右上角。
但是,這是他們的樣子。
我不希望屏幕頂部和兩個按鈕之間有任何空格。 這是我的代碼。
<LinearLayout
android:layout_marginTop="0dp"
android:id="@+id/LinearLayout02"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="@+id/settingsBTN"
android:layout_weight="1"
android:src="@drawable/HomeBTNunpressed"/>
<View android:layout_width="3dp"
android:layout_height="50dp"
android:background="@android:color/black"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="@+id/homeBTN"
android:layout_weight="1"
android:src="@drawable/settingsBTNunpressed"/>
</LinearLayout>
首先,在父級中不要使用fillParent(Deprecated)而是使用MatchParent。
其次,如果使用線性布局並為視圖指定權重,並且您想平等地分配空間,則將寬度0dp和權重1都指定為權重和2。
第三,使用任何包含ImageView的布局為中心,並根據需要指定背景顏色
您正在使用“圖像按鈕”,並且圖像的寬高比被調整為大小,因此不合適。
實際上,您使用的是Image Button,因此邊框實際上是按鈕。您可以使用Image View並使它在您的代碼中可單擊而不是使用image button。我在這里使用了自己的Image,但是您可以在xml中使用自己的Image。
<LinearLayout
android:id="@+id/LinearLayout02"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/settingsBTN"
android:layout_weight=".5"
android:layout_marginTop="0dp"
android:background="#B6B6B6"
android:src="@drawable/username_icon"/>
<View android:layout_width="3dp"
android:layout_height="50dp"
android:background="@android:color/black"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight=".5"
android:layout_marginTop="0dp"
android:background="#B6B6B6"
android:src="@drawable/username_icon"/>
</LinearLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.