2012-02-13 58 views
1

我正在測試應用程序。我需要顯示問題和選項。針對每個問題的選項數量在手之前是未知的。即爲每個問題有不同數量的選項,因此我動態顯示選項如何在android中正確修復佈局?

我的代碼:

list.xml

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

    > 
<com.splash.Header 
     android:id="@+id/layoutheader" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" /> 

<ListView 
android:layout_height="wrap_content" 
android:id="@+id/listview" 
android:layout_width="fill_parent"> 
</ListView> 
</LinearLayout> 

header.xml

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

<ImageView 
    android:id="@+id/topbar" 
    android:layout_width="330dip" 
    android:layout_height="wrap_content" 
    android:background="@drawable/topplain" 
> 
</ImageView> 

<ImageView 
android:id="@+id/home" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:src="@drawable/homebtn" 
android:layout_marginTop="4dp" 
android:layout_alignParentLeft="true" 
> 
</ImageView> 

<ImageView 
android:id="@+id/back" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:background="@drawable/backbtn" 
android:layout_marginTop="4dip"  
android:layout_marginLeft="255dip" 
android:layout_alignParentRight="true" 
android:onClick="back" 
> 
</ImageView> 

</RelativeLayout> 

listitem.xml

<?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="#FFFFFF" 
    android:id="@+id/lnrlayout"> 



    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/tv_question" 
     android:text="" 
     android:textColor="#000000" 
     android:layout_below="@+id/casedescription" 
     android:layout_marginTop="10dp" 
     ></TextView> 



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:id="@+id/rlt_main" 
    android:layout_height="wrap_content"> 
    <LinearLayout 
    android:orientation="vertical" 
    android:id="@+id/chkboxes" 
    android:layout_below="@+id/tv_question" 
    android:layout_alignParentLeft="true" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
     > 


    </LinearLayout> 


    </RelativeLayout> 
</RelativeLayout> 

這裏我的問題是根據問題的大小布局正在擴大否則佈局只顯示如圖所示的半屏。如何解決這個問題。我嘗試了很多來調整佈局,但仍面臨同樣的問題。請幫助我解決這個問題。在此先感謝..

enter image description here

+0

你更好的使用,而不是線性 – Akram 2012-02-13 06:22:11

+0

喜相對佈局哪一個,我應該使用相對layout..is對於列表視圖? – RaagaSudha 2012-02-13 06:23:27

+0

第一個。 – Akram 2012-02-13 06:24:57

回答

0

我猜切斷你的ScrollView標籤列表項內

編輯

<?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:background="#FFFFFF" 
    android:id="@+id/lnrlayout"> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/lnrlayout1"> 

     <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/tv_question" 
     android:text="" 
     android:textColor="#000000" 
     android:layout_marginTop="10dp" 
     ></TextView> 

</LinearLayout> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/rlayout1"> 
<LinearLayout 
    android:orientation="vertical" 
    android:id="@+id/checkboxes" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
     > 


    </LinearLayout> 
</LinearLayout> 
</LinearLayout> 
+0

您好我刪除了滾動,但即使是這樣,我面臨的問題 – RaagaSudha 2012-02-13 07:33:13

+0

我有編輯我的anser嘗試遲到的答案,我不知道它會有幫助與否。只是猜測。另一件事,你真的需要使用相對佈局? – 2012-02-13 08:06:57

+0

嗨我已編輯我的listitem.xml文件..但即使這樣它不工作..plz幫助我 – RaagaSudha 2012-02-13 09:41:32

0

您可以在XML佈局使用layout:weight財產,有您可以爲您的標題列表視圖設置所需的佈局權重。然後,列表視圖和標題寬度將相應調整。 check this for more info

+0

嗨感謝您的迴應...你可以給我一個例子,我的代碼在這裏...先謝謝了 – RaagaSudha 2012-02-13 10:37:52

1

檢查你得給一些「layout_marginBottom」屬性的地方..