RelativeLayout 设置android:layout_centerVertical="true"但不完全居中

十三邵 2014-08-06 03:37:32
    <RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/huiwuxqbj">

<TextView
android:id="@+id/main_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:textColor="#ffffff"
android:textSize="30sp"
android:lines="3"
android:ellipsize="end"
android:textStyle="bold" />
</RelativeLayout>


文字是在布局的垂直中间偏上的位置,而不是在垂直的中间
...全文
3229 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
小cun 2016-08-24
  • 打赏
  • 举报
回复
你可以再加一个android:gravity="center"属性就可以把内容居中了。 你上边那个知识控件相对于父控件居中了。
Raypod 2015-08-02
  • 打赏
  • 举报
回复
我去 你也忒不小心了
Raypod 2015-08-02
  • 打赏
  • 举报
回复
我去 你也忒不小心了
tyxq20112669 2015-08-01
  • 打赏
  • 举报
回复
楼上说得对。
_平凡之路_ 2015-07-23
  • 打赏
  • 举报
回复
确实,你RelativeLayout的android:layout_height是"wrap_content",改成固定值试试。
gamedragon 2014-08-07
  • 打赏
  • 举报
回复
你RelativeLayout的android:layout_height是"wrap_content",你让你的控件怎么垂直居中啊。
dali_yan 2014-08-06
  • 打赏
  • 举报
回复
不知道你是问全屏中间还是说只在当前自适应大小的中间:看下面代码,能够实现你的中间的愿望,这里是全屏中间,如果你这是要布局中间就直接修改 android:layout_height="match_parent" --》android:layout_height="wrap_content",希望能够帮到你。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:background="#fff">

        <TextView
            android:id="@+id/main_content"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:ellipsize="end"
            android:gravity="center"
            android:lines="3"
            android:text="13321"
            android:textColor="#000"
            android:textSize="30dp"
            android:textStyle="bold" />

 </RelativeLayout>
哎,真难 2014-08-06
  • 打赏
  • 举报
回复
是不是RelativeLayout没有fill_parent的原因

80,359

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧