简体   繁体   中英

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.

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"

Use RelativeLayout

    <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="90dp"
            android:background="@drawable/my_background"
            android:layout_alignParentBottom="true"
             >

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                 android:layout_alignParentRight="true"
                android:src="@drawable/my_small_image" />

            </RelativeLayout>

LinearLayout您可以使用 -

android:layout_gravity="bottom|right"

I would recomend Using RelativeLayout but if you have to use LinearLayout i know that android:scaleType" can help center or move image, did you try android:scaleType="fitEnd" or android:scaleType="fitXY"

for more Try This

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM