簡體   English   中英

將ImageView對齊LinearLayout的右下角

[英]Align ImageView to bottom Right of LinearLayout

我正在試圖將一個ImageView放在LinearLayout的右下角....我把代碼編寫為:

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>

此代碼導致右下角的ImageView“my_small_image”,但我需要在左下角。 有人對此有什么想法嗎?

我希望這里有人可以幫助我。

最好的問候和提前感謝,Fadel。

使用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>

這將圖像定位在中心 - 底部,用於右下角

android:layout_gravity="right"

使用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"

我會建議使用RelativeLayout但是如果你必須使用LinearLayout我知道android:scaleType"可以幫助居中或移動圖像,你試過android:scaleType="fitEnd"android:scaleType="fitXY"

更多嘗試這個

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM