Reputation: 349
I want to add my imagebuttom at the right of the screen like this:
Imageview textview ImageButtom
The problem is that I tried everything and it didn't work.
<?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="wrap_content"
android:background="#f5f5f5">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="0dp"
android:id="@+id/card_view"
android:layout_marginBottom="1dp"
android:layout_marginEnd="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp">
<LinearLayout
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/ProfilePic"
android:paddingBottom="20dp"
android:paddingLeft="3dp"
android:adjustViewBounds="true" />
<TextView
android:id="@+id/textViewName"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="20dp"
android:paddingLeft="1dp"
/>
<ImageButton
android:id="@+id/imageButton"
android:layout_width="20dp"
android:layout_height="30dp"
android:src="@mipmap/ic_launcher"
android:contentDescription="..."
android:background="@null"
android:layout_gravity="right|center" />
</LinearLayout>
<ImageView
...
how can I add my ImageButtom at the right of screen? it is for my menu.
thank you friends!
Upvotes: 0
Views: 55
Reputation: 94
Try to change the linear layout on Relative layout, and set android:layout_alignParentEnd="true"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f5f5f5">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="0dp"
android:id="@+id/card_view"
android:layout_marginBottom="1dp"
android:layout_marginEnd="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp"><![CDATA[>
]]></android.support.v7.widget.CardView>
<LinearLayout
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/ProfilePic"
android:layout_width="50dp"
android:layout_height="50dp"
android:adjustViewBounds="true"
android:paddingBottom="20dp"
android:paddingLeft="3dp" />
<TextView
android:id="@+id/textViewName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="20dp"
android:paddingLeft="1dp"
android:textStyle="bold" />
<ImageButton
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:background="@null"
android:contentDescription="..."
android:src="@mipmap/ic_launcher"
android:layout_alignBottom="@+id/ProfilePic"
android:layout_alignParentEnd="true" />
Upvotes: 1
Reputation: 2512
Try seting the layout_weight
attribute of the TextView
to 1, so that it takes the whole space between the ImageView
and the ImageButton
:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/ProfilePic"
android:paddingBottom="20dp"
android:paddingLeft="3dp"
android:adjustViewBounds="true" />
<TextView
android:id="@+id/textViewName"
android:textStyle="bold"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="20dp"
android:paddingLeft="1dp"
/>
<ImageButton
android:id="@+id/imageButton"
android:layout_width="20dp"
android:layout_height="30dp"
android:src="@mipmap/ic_launcher"
android:contentDescription="..."
android:background="@null"
android:layout_gravity="right|center" />
</LinearLayout>
But
I strongly suggest you to take a look at Menus.
Upvotes: 1
Reputation: 15543
You can add a space which has weight=1
and width=0dp
before your ImageButton:
<LinearLayout ...>
<TextView .../>
<Space
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1"/>
<ImageButton .../>
</LinearLayout>
Upvotes: 1