这是可能的布局在Android中? [英] Is this layout possible in Android?

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

问题描述

此布局似乎简单,但我找不到任何办法做到这一点只在XML中使用的LinearLayout 或任何其它布局,而不动态变化的特性。这里是我想要的东西,如果文本短则布局应如图所示完全被包裹的:

This layout seems simple but I can't find any way to do this solely in xml using LinearLayout or any other layout without changing properties dynamically. Here is what I want, if text is short then layout should be totally wrapped as shown in figure:

但万一的TextView 包含较长的文本就应该扩大,但必须留出空间为按钮这样的

But in case TextView contains longer text then it should be expanded but it must leave space for Button like this:

推荐答案

尝试了很多的布局之后,我能做的最好的就是用 TableLayout shrinkColumns

After experimenting a lot of layout, the best that I can do is to use TableLayout with shrinkColumns

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:shrinkColumns="0" >
    <TableRow>
        <TextView
            android:id="@+id/text"
            android:ellipsize="end"
            android:singleLine="true"
            android:text="This is a very long text and it cannot be displayed wholly" />

        <Button
            android:id="@+id/button"
            android:text="Button" />
    </TableRow>
</TableLayout>

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

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