Android的相对布局不能对中心形象 [英] Android Relative Layout can't make image on center

查看:131
本文介绍了Android的相对布局不能对中心形象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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


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

 < 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的特性<一个href=\"http://developer.android.com/reference/android/widget/TextView.html#attr_android%3adrawableLeft\"相对=nofollow> drawableLeft 和drawableRight

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

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

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

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.

这篇关于Android的相对布局不能对中心形象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆