【问题标题】:android layout question安卓布局问题
【发布时间】:2012-04-10 13:39:50
【问题描述】:

目前我正在处理一个由标题、描述、标签和页脚组成的对话框。标题可以很长,在这种情况下,文本应该自动显示在多行中。描述也更长,应该填写多行。 对话框底部必须是页脚(如果标题和描述没有填满整个屏幕)。 我尝试创建所描述的布局,但遇到长文本问题 - 如果内容很长,它不会显示多行但会扩展主视图 (LinearView),因此内容会扩展到可见区域。

我在这里粘贴当前状态的打印屏幕和所需布局的模型: alt text http://img52.imageshack.us/img52/9697/androidscreenshot.png alt text http://img69.imageshack.us/img69/3609/screenshot20091227at716.png

TextView "Footer" 和按钮 OK 和 Cancel 应该出现在屏幕底部,并且标题 ("Title Title Title...) 和描述文本应该自动出现在多行中,而不是扩展父视图。

如果有人能提供解决这些布局问题的提示,我将不胜感激。

谢谢!

【问题讨论】:

    标签: android layout


    【解决方案1】:

    这样的事情应该会有所帮助:将文本元素放在顶部,并使用weightSum 将按钮强制放在布局的底部。我不记得多行文本的设置了,但如果你没有使用设置为true 的singleLine 属性,那么一切都会正常。

    查看XML attribute documentation 了解更多信息。

    <?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"
      android:orientation="vertical"
      android:weightSum="1">
    
      <TextView
        android:id="@id/android:title"
        android:layout_width="fill_parent"
        android:layout_weight="1" />
    
      <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:weightSum="2">
          <Button
            android:id="@+id/btn_ok"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="@string/btn_ok" />
          <Button
            android:id="@+id/btn_cancel"            
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="@string/btn_cancel" />
      </LinearLayout>
    
    </LinearLayout>
    

    【讨论】:

    • 我正要发布一个类似的布局问题,却发现了这个。在此之前我还没有看到 weightSum 属性,但这正是我所需要的。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多