Android 如何同时提供定心和相对布局
这是我试图实现的布局。所以我知道如何居中和左右对齐,但当我与RelativeLayout结合时,我并没有得到想要的结果。除非添加边距/填充,否则文本视图都将向左。我有左-右中心的右公式,但当我想把一些文本放在它们旁边时,它不起作用Android 如何同时提供定心和相对布局,android,android-layout,Android,Android Layout,这是我试图实现的布局。所以我知道如何居中和左右对齐,但当我与RelativeLayout结合时,我并没有得到想要的结果。除非添加边距/填充,否则文本视图都将向左。我有左-右中心的右公式,但当我想把一些文本放在它们旁边时,它不起作用 <ImageView> <TextView> <ImageView><TextView> <ImageView><TextView> 这是我的布局(它只包含一个文本,需要大量的
<ImageView> <TextView> <ImageView><TextView> <ImageView><TextView>
这是我的布局(它只包含一个文本,需要大量的页边空白,因为它太过左边了:
<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
<ImageView android:id="@+id/reply_button" android:src="@drawable/icons_reply"
android:layout_width="60dp" andorid_layout_alignParentLeft="true" android:layout_height="wrap_content" android:paddingRight="5dp"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Reply"
android:layout_alignLeft="@+id/reply_button" android:layout_marginLeft="50dip" android:textSize="12sp"/>
<ImageView android:id="@+id/resend_button" android:src="@drawable/icons_resend"
android:layout_width="60dp" android:layout_height="wrap_content" android:layout_centerInParent="true" android:paddingRight="5dp"/>
<ImageView android:id="@+id/select_button" android:focusableInTouchMode="false" android:focusable="false" android:layout_alignParentRight="true" android:src="@drawable/select_icon"
android:layout_width="60dp" android:layout_height="wrap_content" android:paddingRight="5dp"/>
</RelativeLayout>
您不需要在每个
文本视图的左侧设置图像视图
,只需在文本视图
的左侧设置一个可绘制的左组合视图,并将其放置在线性布局中
:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
<TextView
...
android:drawableLeft="@drawable/yourimage"
android:drawablePadding="3dp" //optional, if you want some padding
android:gravity="center_vertical" // to center vertically the text and drawable
weight="1" // use this in a LinearLayout so they will be
// uniformly distributed over the space
...
/>
</LinearLayout>
您应该将它们嵌套在其他相关布局中,并将它们放在一个大的线性布局中
<LinearLayout.....>
<RelativeLayout
android:weight=1>
<image>
<Text>
</RelativeLayout>
<RelativeLayout
android:weight=1
>
<image>
<Text>
</RelativeLayout>
<RelativeLayout
android:weight=1>
<image>
<Text>
</RelativeLayout>
</LinearLayout>
您可以将整个文本视图设置为可点击。其他解决方案也可以,它们只会消耗更多资源