2015-07-09 69 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