2013-08-22 140 views
-1

我有一个问题与我的列表视图它应该有一个按钮在顶部和下方是列表视图。列表视图不能正确显示为图形布局

但是,当我运行我的应用程序时,listview完全覆盖了按钮。这个问题的主要原因是什么?

编辑 - 遗憾的大图像,我不知道如何调整他们

enter image description here

enter image description here

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

<Button 
    android:id="@+id/buttonList" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:onClick="onClick" 
    android:text="@string/buttonShow" /> 

<ListView 
    android:id="@+id/listDays" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/buttonList"/> 

</RelativeLayout> 


public class SimpleListView extends ListActivity{ 

    String[] days; 
    Button mButtonList; 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     mButtonList = (Button)findViewById(R.id.buttonList); 
     //mButtonList.setOnClickListener(btnListener); 

     //setContentView(R.layout.activity_list); 

     ListView lstView = getListView(); 
     lstView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); 

     days = getResources().getStringArray(R.array.daysArray); 
     setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_checked, days)); 
     } 

回答

0

你可以使用这个简单:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<LinearLayout 
    android:id="@+id/tab2" 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="0.1" 
    android:orientation="vertical" > 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Button" /> 
</LinearLayout> 

<LinearLayout 
    android:id="@+id/tab3" 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="0.9" 
    android:orientation="vertical" > 

    <ListView 
     android:id="@+id/listView1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
    </ListView> 

</LinearLayout> 

+0

我试过这个,看起来好像会起作用,但问题仍然存在。我会添加java代码,因为那里可能有问题吗? – user2663646

+0

首先,你必须在你的Java类中调用SetContentVIew方法.. – Piyush

+0

我不得不评论说,因为使用它会使活动崩溃。 “活动已停止”错误消息。 – user2663646

0

您需要提供的代码,如果您希望我们能够修复它。请提供您的xml布局。但是,如果没有进一步的信息,可能是因为你的XML布局有问题。下面是一个布局可能会为你工作:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
> 
<Button 
    android:id="@+id/header_button" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
/> 
<ListView 
     android:id="@android:id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:dividerHeight="1dip" 
     android:paddingLeft="1dp" 
     android:layout_below="@id/header_button" 
     /> 
</RelativeLayout> 
+0

我在xml和class的代码中编辑过,xml非常相似,最初使用的是linearlayout。但改为亲属也不幸没有奏效。 – user2663646

0

您的XML代码看起来大约右

你设置该属性在代码中的任何地方都可见。

+0

nope,绝对没有那个地方,看起来很奇怪。 – user2663646

相关问题