2012-02-13 61 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”属性的地方..