Android的布局混乱 [英] Android layout confusing

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

问题描述

下面是我拍摄的图片:结果

Here is my capture picture:

这是我的code:


<RelativeLayout
    android:id="@+id/wrapper"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:gravity="left">

    <TextView
        android:id="@+id/timeIn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"  
        android:layout_toRightOf="@+id/messageIn"          
        android:layout_gravity="center"
        android:layout_marginTop="15dip"
        android:text="23:23"/>

    <TextView
        android:id="@+id/messageIn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"       
        android:layout_gravity="center"
        android:layout_margin="5dip"
        android:background="@drawable/bubble_yellow"
        android:paddingLeft="10dip"
        android:text="HIHIHIHIHIHI" />



</RelativeLayout>

然而,如果文本HIHIHIHIHIHI变为HIHIHIHIHIHIHIHIHIHIHIHIHIHIHIHIHIHI:
时间会丢失,泡沫将填补父结果

However, if the text "HIHIHIHIHIHI" changes to "HIHIHIHIHIHIHIHIHIHIHIHIHIHIHIHIHIHI": the time will missing and the bubble will fill parent

我怎么能这样做的时候还是会以气泡的权利,即使文字MULT行?

How can I do so that the time will still to the right of the bubble even the text is mult-line?

推荐答案

试试这个

<RelativeLayout
    android:id="@+id/wrapper"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:gravity="left">

    <TextView
        android:id="@+id/timeIn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"           
        android:layout_gravity="center"
        android:layout_marginTop="15dip"
        android:layout_alignParentRight="true"
        android:text="23:23"/>

    <TextView
        android:id="@+id/messageIn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"       
        android:layout_gravity="center"
        android:layout_margin="5dip"
        android:background="@drawable/bubble_yellow"
        android:layout_toLeftOf="@+id/timeIn" 
        android:layout_alignParentLeft="true" 
        android:paddingLeft="10dip"
        android:text="HIHIHIHIHIHI" />

</RelativeLayout>

要对小文还(要调整根据消息messageIn的宽度)和时间信息出现的工作权利(而不是右对齐)

To work for small texts also (To resize the width of messageIn according to message) and time to appear right of message (not right aligned)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/wrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="1.0" >

<LinearLayout
    android:id="@+id/lin_lay1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1.0" >

    <TextView
        android:id="@+id/messageIn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="5dip"
        android:background="@drawable/bubble_yellow"
        android:paddingLeft="10dip"
        android:text="HIHIHI" />
</LinearLayout>

<LinearLayout
    android:id="@+id/lin_lay2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="0.1" >

    <TextView
        android:id="@+id/timeIn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="15dip"
        android:padding="5dp"
        android:text="23:23" />
</LinearLayout>

</LinearLayout>

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

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