2011-09-23 61 views
0

我试图用相对布局在UI应该在哪里寻找这样创建UI:UI的相对布局

  1. 在屏幕上,我有一个TextView紧接着又TextView的
  2. 顶部
  3. 其次滚动视图在哪里我必须显示 可滚动格式的文本
  4. 最后我有一个imageview。

我该如何做到这一点。 我尝试过使用相对和线性布局的组合,但元素会重叠。任何人有任何建议如何进行?

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" android:layout_height="fill_parent" 
android:background="@drawable/background_main"  android:id="@+id/g_description"> 
<TextView android:id="@+id/titleBar" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:background="@drawable/header" 
    android:layout_alignParentTop="true" android:gravity="center" 
    android:text="@string/aboutus" android:textAppearance="? android:attr/textAppearanceLarge" 
    android:textStyle="bold" /> 

<TextView android:id="@+id/wd_name" 
    android:layout_width="fill_parent" android:layout_below="@id/titleBar" 
    android:layout_height="wrap_content" android:textStyle="bold" 
    android:textColor="#FFFFFF" android:textSize="18dip" 
    android:background="@drawable/background_main" android:gravity="center" /> 

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scrolltext" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:layout_below="@id/wd_name" 
    android:padding="5dip"> 
    <LinearLayout android:orientation="vertical" 
     android:layout_width="fill_parent" android:layout_height="fill_parent"> 

     <TextView xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/wd_description" 
      android:layout_width="fill_parent" android:layout_height="wrap_content" 
      android:textSize="14dip" android:textColor="#FFFFFF"> 
     </TextView> 
     </LinearLayout> 

</ScrollView>   


<ImageView android:id="@+id/bottomBar" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:src="@drawable/bottom_bar" 
    android:layout_alignParentBottom="true" /> 

+0

发布您正在尝试的xml代码。 –

回答

0

它适用于每个文本视图设置android:orientation =“vertical”。

1

,你可以这样实现它:

  1. 采取relative layout和它把textview
  2. 以另一个textview并将其添加到它android:layout_below="id of the 1st textview"
  3. scrollview并将其添加到它android:layout_below="id of the 2nd textview"
  4. 以滚动视图内的linear layout
  5. textview置于线性布局内。
  6. imageview并将其添加到android:layout_below="id of the scrollview"

现在你的布局已准备就绪,如果你得到任何错误,那么让我知道你的代码....

+1

ScrollView与第二个TextView重叠。而我没有得到任何滚动的财产。 – AndroGeek

+0

在scrollview标签中使用android:layout_marginTop属性,如果您获得重叠问题....当内容不适合可用空间时,您将看到scrollview ... –

0

如果您有一系列要流下来的画面元素,然后将其听起来像你只需要一个LinearLayout

0

它如下。在scrollview中放置一个TextView将使它可以滚动。重置是自选的。

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


    <TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="Below TOP TextView" android:id="@+id/TextView01" android:layout_alignParentTop="true"></TextView> 

    <TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="TOP TextView" android:id="@+id/TextView02" android:layout_below="@id/TextView01"></TextView> 

    <ScrollView android:layout_height="wrap_content" android:layout_width="fill_parent" android:fillViewport="true" android:layout_below="@id/TextView02"> 
    <TextView android:id="@+id/textView1" android:layout_height="wrap_content" android:text="Scrollable textViewafkasjf;laksjflaskjf;lasjf;alsfjal;sfj;aslfj;aslfja;slfj;aslkfj;asldfj;aslkfjasl;dfj;a asfj aslfj asldfjk as;lfjk asfjka;sldf jl;asj df;asdfjasfj aslfj asljf asjfl;asfasj fasj f;asj flas jf;lasjf;asjkf;las f;asj df;as jf;lasjf ;asjf;asjf;asjf;asjf;asjf;jasf;asfja s;dfa;sf asf jf asf a; sldfja;slfj;asldfjk" android:layout_width="fill_parent"></TextView> 
    </ScrollView> 
    <ImageView android:src="@drawable/icon" android:layout_height="wrap_content" android:id="@+id/imageView1" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_width="fill_parent"></ImageView> 

</RelativeLayout> 
+1

没有运气..不起作用 – AndroGeek

+0

我不知道为什么它不适合你,在我的机器上似乎很好。 –

+1

现在正在工作。我为每个文本视图设置了android:orientation =“vertical”。感谢帮助!! – AndroGeek