Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align ImageView to bottom Right of LinearLayout

I'm triying to put an ImageView in bottom right of LinearLayout .... I wrote the code as bellow :

style.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="90dp"
        android:background="@drawable/my_background"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|right"
            android:src="@drawable/my_small_image" />

        </LinearLayout>

    <ListView  
        android:id="@android:id/list"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"/>

</LinearLayout>

This code results in the ImageView 'my_small_image' at the bottom right, but I need it in the bottom left. Anyone have any ideas about this?

I hope somebody here can help me.

Best regards and thanks in advance, Fadel.

like image 939
BinaryMan Avatar asked Sep 24 '13 17:09

BinaryMan


People also ask

How do I fix the view to the bottom of LinearLayout?

You can set the layout_height="0dp" of your header, footer and ScrollView and define a layout_weight .

Is LinearLayout deprecated?

This constant was deprecated in API level 28.

How to set linear layout in android studio?

To create a linear layout in which each child uses the same amount of space on the screen, set the android:layout_height of each view to "0dp" (for a vertical layout) or the android:layout_width of each view to "0dp" (for a horizontal layout). Then set the android:layout_weight of each view to "1" .

What is LinearLayout?

Android LinearLayout organizes elements along a single line. We can specify whether that line is vertical or horizontal using android:orientation . The orientation is horizontal by default.


1 Answers

Using LinearLayout is possible:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    android:orientation="vertical">

    <!-- other elements in linear layout here -->
    <!-- making a RelativeLayout un-desirable -->

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="0dp"       
        android:layout_gravity="center"   
        android:layout_weight="1"         
        android:scaleType="fitEnd"        
        android:src="@drawable/your_image" />

</LinearLayout>

This will position the image at the center-bottom, for bottom-right use

android:layout_gravity="right"
like image 103
Entreco Avatar answered Nov 07 '22 07:11

Entreco