首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >相对布局- toRightOf和CenterInParent

相对布局- toRightOf和CenterInParent
EN

Stack Overflow用户
提问于 2018-07-17 22:19:11
回答 2查看 270关注 0票数 0

如何才能拥有这种布局方式:

包含2个元素的相对布局:图标位于左侧,文本视图居中于父级。问题是,当文本变大时,它会覆盖图像,因为它的宽度是"wrap_content“。

如何解决这个问题?

http://prntscr.com/k8shpm期望的结果

EN

回答 2

Stack Overflow用户

发布于 2018-07-17 22:31:44

如果你知道图标的宽度,你总是可以这样做:

代码语言:javascript
复制
<?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="wrap_content">

<ImageView
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:background="@android:color/black"/>

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="50dp"
    android:gravity="center"
    android:text="Loremem ipsum Lorem ipsum Lorem ipsum"/>

票数 0
EN

Stack Overflow用户

发布于 2018-07-17 22:31:51

我从你的解释中理解到的是,你需要这样的东西

代码语言:javascript
复制
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
    android:id="@+id/image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:src="@mipmap/ic_launcher" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:layout_toRightOf="@+id/image"
    android:layout_centerVertical="true"
    android:gravity="center">

    <TextView
        android:id="@+id/tvMessage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="the quick brown fox jump over the lazy dog" />
</LinearLayout></RelativeLayout>

如果这不是你想要的,那么请发布你的代码来帮助理解这个问题

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51383758

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档