Android的相对布局不能对中心形象布局、形象、中心、Android

由网友(萤梦)分享简介:您好我设法让与线性视图中的文本图标中心同一行,但我想在箭头的图像在右侧添加,所以我必须切换到相对的观点。正如图中所示,我不能设法设置相对视图左侧的图标看起来像线性视图。 修改结果我想箭头右边的图标风格。 结果左图是线性的,右边是相对的。 < RelativeLayout的的xmlns:机器人=htt​​p://s...

您好我设法让与线性视图中的文本图标中心同一行,但我想在箭头的图像在右侧添加,所以我必须切换到相对的观点。正如图中所示,我不能设法设置相对视图左侧的图标看起来像线性视图。

修改结果我想箭头右边的图标风格。

结果左图是线性的,右边是相对的。

 < RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android机器人:ID =@ + ID / layercontainer机器人:方向=横向机器人:layout_width =FILL_PARENT机器人:layout_height =FILL_PARENT机器人:填充=10dp>< ImageView的机器人:ID =@ + ID / categoryIcon    机器人:layout_width =WRAP_CONTENT    机器人:layout_height =FILL_PARENT    机器人:重力=center_vertical    机器人:layout_alignParentTop =真    机器人:layout_alignParentLeft =真    机器人:layout_alignParentBottom =真    机器人:layout_marginRight =15dp    机器人:layout_marginTop =5DP    机器人:layout_marginBottom =5DP/>< TextView的机器人:ID =@ + ID / categoryTitle    机器人:layout_width =WRAP_CONTENT    机器人:layout_height =FILL_PARENT    机器人:重力=center_vertical    机器人:layout_alignParentTop =真    机器人:layout_alignParentBottom =真    机器人:layout_toRightOf =@ ID / categoryIcon    机器人:文字样式=大胆    机器人:TEXTSIZE =22dp    机器人:文字颜色=#000000    机器人:layout_marginTop =5DP    机器人:layout_marginBottom =5DP/>< ImageView的        机器人:ID =@ + ID / nextIcon        机器人:layout_width =WRAP_CONTENT        机器人:layout_height =WRAP_CONTENT        机器人:重力=center_vertical        机器人:layout_alignParentTop =真        机器人:layout_alignParentBottom =真        机器人:layout_alignParentRight =真        机器人:layout_marginTop =5DP        机器人:layout_marginBottom =5DP/>< / RelativeLayout的> 

解决方案

我建议使用TextView的特性 drawableLeft 和drawableRight

 的android:drawableLeft =@绘制/不管机器人:drawableRight =@绘制/箭头机器人:宽=FILL_PARENT 

这方式和TextView中的重力设置为中心,一切都应该是确定

此外,使用单一的TextView,而不是一个RelativeLayout的+ 3​​次是简单一个大的提升。无论如何,如果你要坚持到3次,使用的LinearLayout代替的RelativeLayout是一个很好的建议。

android动态写布局,Android中在activity用代码动态添加布局

Hi i manage to make the icon center same line with the text in linear view, but I wanna add in a arrow image at the right side so i have to switch to relative view. As shown in the image, I can't manage to set the relative view left icon look like linear view.

EDIT I want to arrow icon stay on the right.

Left image is linear, right is relative.

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layercontainer"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp">
<ImageView android:id="@+id/categoryIcon"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:gravity="center_vertical"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentBottom="true"
    android:layout_marginRight="15dp"
    android:layout_marginTop="5dp"
    android:layout_marginBottom="5dp" />
<TextView android:id="@+id/categoryTitle"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:gravity="center_vertical"
    android:layout_alignParentTop="true"
    android:layout_alignParentBottom="true"
    android:layout_toRightOf="@id/categoryIcon"
    android:textStyle="bold"
    android:textSize="22dp"
    android:textColor="#000000"
    android:layout_marginTop="5dp"
    android:layout_marginBottom="5dp" />
<ImageView
        android:id="@+id/nextIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"/>
</RelativeLayout>

解决方案

I suggest using the TextView properties drawableLeft and drawableRight

android:drawableLeft="@drawable/whatever"
android:drawableRight="@drawable/arrow"
android:width="fill_parent"

That way and setting the TextView's gravity to center, everything should be ok

Also, using a single TextView instead of a RelativeLayout + 3 views is a big improvement in simplicity. Anyway, if you were to stick to 3 views, using LinearLayout instead of RelativeLayout is a good advice.

阅读全文

相关推荐

最新文章