2011-09-23 63 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