Android ImageView布局对齐

时间:2014-02-08 07:43:36

标签: android imageview alignment

如何更改布局以使图像1更像图像2?我不介意它是向上移动的文本还是向上移动的图像。

What I have

What I need

我的布局文件是这样的: -

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="1"
        android:orientation="horizontal" >

        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="0.6"
            android:orientation="vertical" >

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:src="@drawable/imp" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="0.4"
            android:orientation="vertical" >

            <LinearLayout 
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/stats_chr" />
                <TextView
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="right|center_vertical"
                    android:singleLine="true"
                    android:text="AA" />
            </LinearLayout>

2 个答案:

答案 0 :(得分:4)

接受的答案对我不起作用。这是我的解决方案

将android:scaleType =“fitStart”添加到ImageView。

答案 1 :(得分:0)

试试这个..

android:gravity="top"使用LinearLayoutandroid:layout_gravity="top"使用ImageView

       <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:gravity="top"
            android:layout_weight="0.6"
            android:orientation="vertical" >

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="top"
                android:src="@drawable/imp" />

        </LinearLayout>