我有以下布局:
<LinearLayout 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:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:orientation="vertical" tools:context=".MainActivity" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Status:" android:layout_gravity="left" android:textAppearance="?android:attr/textAppearanceMedium" /> <ImageView android:id="@+id/txcpluss_imageView_refresh" android:layout_width="30dp" android:layout_height="30dp" android:layout_gravity="right" android:clickable="true" android:contentDescription="icon" android:gravity="right" android:src="@drawable/refresh_big" /> </LinearLayout> </LinearLayout>
但我的刷新图标不在我想要的右上角.它就在文本视图旁边.
如何让文本视图位于左侧,右侧的刷新图标位于左侧?
解决方法
使用以下代码
<LinearLayout 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:orientation="vertical" 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=".MainActivity" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/textView1" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="left" android:layout_weight="1" android:text="Status:" android:textAppearance="?android:attr/textAppearanceMedium" /> <ImageView android:id="@+id/txcpluss_imageView_refresh" android:layout_width="30dp" android:layout_height="30dp" android:layout_gravity="right" android:clickable="true" android:contentDescription="icon" android:gravity="right" android:src="@drawable/refresh_big" /> </LinearLayout>
我为文本视图添加了权重.