【问题标题】:ui layout design stuck hereui布局设计卡在这里
【发布时间】:2012-12-12 07:14:47
【问题描述】:

我有两个带有两种颜色的文本视图

  1. “qwer tyu iopasd fgh jkl zxcv bnm”和
  2. “123456789”

我想设计文本视图,例如在“qwer tyu iopasd fgh jkl zxcv bnm”旁边显示没有任何空格“123456789” 如果第一个 textview 到大约 2 到 3 行,那该怎么办?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="qwer tyu iopasd fgh jkl zxcv bnm"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="123456789"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

【问题讨论】:

  • android:layout_marginLeft="5dip" 用于textView2
  • @kumaand 如果第一个文本太大并且填充到 1 行半,那么它不起作用

标签: android textview ui-design


【解决方案1】:

我对这两个文本都给予了重视:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weightSum="1">
    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="qwer tyu iopasd fgh jkl zxcv bnm"
        android:textAppearance="?android:attr/textAppearanceLarge" 
        android:layout_weight="0.50"/>
    <TextView
        android:id="@+id/textView2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="123456789"
        android:textAppearance="?android:attr/textAppearanceLarge" 
        android:layout_weight="0.50"
        android:paddingLeft="15dp"/>
</LinearLayout>*

【讨论】:

  • 你也可以给背景颜色....如果你想要屏幕截图,我也会发布它......
  • 你也可以给textview添加背景
  • 不,它不起作用,我想像 qwer tyu iopasd fgh jkl zxcv bnm 123456789 那样显示它
  • 如果第一个文本视图大约是 2 到 3 行,那么我想在 textview1 结束的 2 或 3 行中显示 textview2
【解决方案2】:

如果您希望文本视图在同一行中一个接一个地显示,请使用LinearLayout 中的属性 android:orientation="horizontal"

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

如果你想在其他下面添加文本视图,你应该使用属性android:orientation="vertical"

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

没有边距和内边距

更新答案 这是另一个解决方案

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:shrinkColumns="*" >

<TableRow
    android:id="@+id/give_id"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="qwer tyu iopasd fgh jkl zxcv bnm"
    android:maxLines="3" />
<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="123456789"
    />
</TableRow>
</TableLayout>

【讨论】:

  • 如果第一个文本视图大约是 2 到 3 行,那么你如何应用这个条件?
  • 你可以在你的文本视图中给出 max lines 属性,给它们 2 或 3 行你想要的,否则你可以为此使用表格布局
  • 如果我必须使用,在你的情况下,我更喜欢使用 tablelayout 而不是 linearlayout。
  • 当第一个文本值增加然后它不起作用时它不起作用
  • 试试我更新的答案,我在这里检查了它的工作正常
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-09-01
  • 2020-06-05
  • 2012-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-07-25
相关资源
最近更新 更多