0

I'm fairly new to Android Studios so sorry if this may come of as a stupid question. I'm trying to put two buttons on the top of my screen. I want them to be in the top left and right corner like in this image.

screen-top buttons

However this is what they look like.

actual button layout

I don't want any space between the top of the screen and the two buttons. This is my code.. 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>
Sebastian Pakieła
  • 2,970
  • 1
  • 16
  • 24
moe_nyc
  • 307
  • 1
  • 4
  • 18

2 Answers2

0

First of all in parent don't use fillParent(Deprecated) rather use MatchParent.

Second if using linear layout and specifying weight for view and in your case you want to devide space equally then specify width 0dp and weight 1 to both and weightsum 2.

Third use any layout containing ImageView at center and specify background color to whatever you want

You are using Image Button, and image gets resized in aspect ratio so don't fit accordingly.

Neeraj Kumar
  • 943
  • 4
  • 16
0

Actually you are using Image Button so that border is actually of button.Instead of using image button you can use Image View and make it clickable in your code.I have used my own Image here but you can use your own Image in your 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>
arps
  • 407
  • 1
  • 3
  • 11
  • mImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // do stuff } }); – arps May 10 '16 at 17:38
  • ok ... so you used java to set a listener up ... also according to [reference/android/widget/ImageView](http://developer.android.com/reference/android/widget/ImageView.html), ImageView elements can have a `android:onClick` attribute (inherited from View) ... thanks ... – dsdsdsdsd May 10 '16 at 17:51