开发者

android layout question

Currently I'm working on a 开发者_StackOverflow中文版dialog which consists of title, description, tags and footer. The title can be long and in this case the text should automatically be displayed in multiple lines. The description is also longer and should fill multiple lines. At the bottom of the dialog has to be the footer (also if the title and description don't fill whole screen). I tried to do create the layout described about but had a problem with long text - if the content is long it doesn't display multiple lines but extends main view (LinearView) so the content extends over the visible area.

Here I'm pasting the print screen of the current state and the mockup of the desired layout: alt text http://img52.imageshack.us/img52/9697/androidscreenshot.png alt text http://img69.imageshack.us/img69/3609/screenshot20091227at716.png

TextView "Footer" and buttons OK and Cancel should appear at the bottom of the screen and the title ("Title Title Title...) and description text should automatically appear in multiple lines instead of extending the parent view.

I would really appreciate if anyone of you could give a tip about solving these layout issues.

Thanks!


Something like this should help: placing the text elements up top, and forcing the buttons to the bottom of the layout using weightSum. I can't remember the settings for multi-line text offhand, but if you're not using the singleLine attribute set to true, then things should work out ok.

Check the XML attribute documentation for more info.

<?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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜