2015-07-09 87 views
0

我對Android Studios相當陌生,所以很抱歉,如果這可能是一個愚蠢的問題。 我試圖把兩個按鈕放在我的屏幕上。我希望他們像這張圖片一樣在左上角和右下角。將按鈕放在屏幕的左上角

screen-top buttons

然而,這是他們的樣子。

actual button layout

我不想在屏幕的頂部和兩個按鍵之間的任何空間。這是我的代碼.. 的LinearLayout

<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> 
+1

這可能會幫助:http://stackoverflow.com/questions/17960599/how-to-remove-padding-around-buttons-in-android – smoggers

+0

也許你有你的佈局的根視圖填充 –

+0

此屏幕 –

回答

0

首先在父母的不使用fillParent(已取消),而使用MatchParent。

二如果使用線性佈局和用於視圖和你的情況指定體重要同樣devide空間然後指定寬度0dp和重量1到兩個並weightsum 2.

第三使用含有ImageView的在中心的任何佈局和指定背景顏色爲任何你想要的

你正在使用圖像按鈕,圖像的高寬比調整大小,因此不適合。

0

其實你正在使用圖像按鈕,以便邊框實際上是按鈕。代替使用圖像按鈕,您可以使用圖像視圖,並使其在代碼中可點擊。我在這裏使用了我自己的圖像,但您可以使用自己的圖像在你的XML。

<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> 
+0

後完整的XML文件,能否請你展示如何使點擊的... – dsdsdsdsd

+0

mImageView.setOnClickListener(新View.OnClickListener(){ @覆蓋 公共無效的onClick(查看視圖){ // do stuff } }); – arps

+0

好吧...所以你用java來設置一個偵聽器...也根據[reference/android/widget/ImageView](http://developer.android.com/reference/android/widget/ImageView.html) ,ImageView元素可以有一個'android:onClick'屬性(繼承自View)...謝謝... – dsdsdsdsd