如何对齐ImageView和TextView左侧和右侧?

时间:2015-01-09 15:05:28

标签: android layout textview imageview

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="end"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.ayush.ebook.MainActivity$PlaceholderFragment" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:src="@drawable/imb" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/imageView1"
    android:layout_alignParentRight="true"
    android:layout_alignTop="@+id/imageView1"
    android:layout_toRightOf="@+id/imageView1"
    android:background="@drawable/a"
    android:textAppearance="?android:attr/textAppearanceMedium" /></RelativeLayout>

这是我的布局。我在左侧有一个ImageView,在右侧有TextView。当我将ScrollView添加到其中时,LinearLayout会使其上下移动。我需要一个ScrollView以及我对齐ImageView和TextView的方式。

帮助我!

1 个答案:

答案 0 :(得分:8)

为左侧添加:

android:layout_alignParentLeft="true"

这是右侧:

android:layout_alignParentRight="true"

复制此内容:

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:src="@drawable/imb"
    android:layout_alignParentLeft="true" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/imageView1"
    android:layout_alignParentRight="true"
    android:layout_alignTop="@+id/imageView1"
    android:layout_toRightOf="@+id/imageView1"
    android:background="@drawable/a"
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:layout_alignParentRight="true"/></RelativeLayout>