简体   繁体   English

将ImageView对齐LinearLayout的右下角

[英]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 : 我正在试图将一个ImageView放在LinearLayout的右下角....我把代码编写为:

style.xml: 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. 此代码导致右下角的ImageView“my_small_image”,但我需要在左下角。 Anyone have any ideas about this? 有人对此有什么想法吗?

I hope somebody here can help me. 我希望这里有人可以帮助我。

Best regards and thanks in advance, Fadel. 最好的问候和提前感谢,Fadel。

Using LinearLayout is possible: 使用LinearLayout是可能的:

<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

    <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" 我会建议使用RelativeLayout但是如果你必须使用LinearLayout我知道android:scaleType"可以帮助居中或移动图像,你试过android:scaleType="fitEnd"android:scaleType="fitXY"

for more Try This 更多尝试这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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