how to get image icon to align right in a Linear Layout?

M.Bill

I know there are lots of threads with more or less same topic but none of them covers my situation:

I have a little garbage can for the delete button but it always disappears off the screen if the line of the text is too long and if its too short it's attached to the line and I just wanted to be on the right hand side of the app like the the Add_item button but since it is in a Linear Layout it does not work

ativity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.owner.test24.MainActivity">

<TextView
    android:id="@+id/header"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/header"
    android:gravity="center_vertical"
    android:textColor="@color/accent"
    android:textSize="24sp" />
 <ImageButton
    android:id="@+id/add_item"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent"
    android:layout_alignEnd="@+id/header"
    android:layout_alignRight="@+id/header"
    android:src="@drawable/add_item_button"
    android:contentDescription="@string/add_item"/>
<ListView
    android:id="@+id/todo_list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/header"/>

 </RelativeLayout>

to_do_item_layout.xml

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">

<CheckBox
    android:id="@+id/checkBox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/item"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="20sp"/>

<ImageButton
    android:id="@+id/btnDel"
    android:src="@drawable/ic_delete_button"
    android:background="@android:color/transparent"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Delete"
    />

if someone has solution please let me know.

shahid17june
use it, it works on every screen size

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:weightSum="1">

    <CheckBox
        android:id="@+id/checkBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_weight="0.03"/>

    <TextView
        android:id="@+id/item"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="hhhhh"
        android:gravity="center_horizontal"
        android:textSize="20sp"
        android:layout_weight="0.87"/>

    <ImageButton
        android:id="@+id/btnDel"
        android:src="@drawable/delete_icon"
        android:background="@android:color/transparent"
        android:layout_width="wrap_content"
        android:layout_gravity="end|center_vertical"
        android:layout_height="wrap_content"
        android:text="Delete"
        android:layout_weight="0.1" />
    </LinearLayout>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to right align in linear layout

From Dev

How to align ImageView & TextView align right in a Linear Layout

From Dev

How to align an icon to the right of content

From Dev

Align Image View to top of the screen in a linear layout

From Dev

How to achieve that background image doesn't get stretched on linear layout

From Dev

How to align linear layout with gridview at the center of screen?

From Dev

how to align the button at bottom in linear layout?

From Dev

How to align buttons below textview in linear layout

From Dev

How to align Image to right in iText?

From Dev

How to align icon to the left with text to the right?

From Dev

How to align material icon on right of a input field?

From Dev

how to design right to left linear layout

From Dev

How to get icon image

From Dev

How to align image right in lightbox when clicked

From Dev

How align Image on right side of div?

From Dev

How to right Align the image on the Toolbar in Android

From Dev

How to vertically center and right-align an image?

From Dev

How to center fit image in linear layout?

From Dev

How to align items justified in android linear layout horizontal orientation?

From Dev

Align icon to the right in a table cell?

From Dev

How to get right column to align vertically

From Dev

How to Get Child position for Linear layout

From Dev

image, then align text to right

From Dev

Align text to right of Image

From Dev

Aligning the image in the Linear Layout

From Dev

Centering the Image in Linear Layout

From Dev

Centering the Image in Linear Layout

From Dev

Aligning the image in the Linear Layout

From Dev

In XML how to align two elements (or widgets) to the right w/ Relative Layout?

Related Related

HotTag

Archive