2012-07-13 113 views
-1

我有一个按钮,列表视图和另一个按钮。最初的ListView有属性不见了,所以button2显示在按钮1的下方,当我点击button1时,按钮2应该设置在该屏幕的底部,名单应当在两个按键之间可见.....如何管理两个按钮之间的列表视图

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <RelativeLayout android:layout_width="fill_parent" 
     android:id="@+id/relativeLayout1" android:layout_height="wrap_content"> 
     <Button android:layout_width="fill_parent" android:id="@+id/Button01" 
      android:background="#ffffff" android:text="Button" 
      android:layout_height="40dp"></Button> 
     <ListView android:layout_height="fill_parent" 
      android:layout_width="fill_parent" android:id="@+id/llList"></ListView> 
     <Button android:layout_height="40dp" android:text="Button" 
      android:id="@+id/button" android:background="#ffffff" 
      android:layout_width="fill_parent"></Button> 
    </RelativeLayout> 
</LinearLayout> 

活动

package com.app.app.hello; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.view.ViewGroup; 
import android.view.View.OnClickListener; 
import android.widget.BaseAdapter; 
import android.widget.Button; 
import android.widget.ListView; 

public class HelloActivity extends Activity { 


    ListView llList; 
    Button btn2,btn1; 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     llList=(ListView) findViewById(R.id.llList); 

     llList.setVisibility(View.GONE); 

     myAdapter adapter=new myAdapter(); 

     llList.setAdapter(adapter); 

     btn2=(Button) findViewById(R.id.button); 

     Button btn1=(Button) findViewById(R.id.Button01); 


     btn1.setOnClickListener(new OnClickListener() { 

      public void onClick(View v) { 


       llList.setVisibility(View.VISIBLE); 
      } 
     }); 
    } 

    class myAdapter extends BaseAdapter 
    { 

     public int getCount() { 
      // TODO Auto-generated method stub 
      return 5; 
     } 

     public Object getItem(int position) { 
      // TODO Auto-generated method stub 
      return position; 
     } 

     public long getItemId(int position) { 
      // TODO Auto-generated method stub 
      return position; 
     } 

     public View getView(int position, View convertView, ViewGroup parent) { 

      View row=View.inflate(HelloActivity.this,R.layout.list_row, null); 
      // TODO Auto-generated method stub 
      return row; 
     } 

    } 
} 

enter image description here

+0

是什么?你试试? – Sajmon 2012-07-13 17:54:12

+0

张贴你的java代码.. – 2012-07-13 18:09:22

+0

最初我使用了去listview的属性,在按钮上点击可见的listview,我不想给列表视图,因为多设备分辨率,我在列表视图上使用fill-parent属性,但问题是,我不能管理listview下面的按钮,它应该在屏幕的底部.... – 2012-07-13 18:10:36

回答

1

使用此活动代码:

public class AbcActivity extends Activity { 
    Button btn1, btn2; 
    ListView lv1; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.two); 

     btn1 = (Button) findViewById(R.id.Button01); 
     btn2 = (Button) findViewById(R.id.button); 
     lv1 = (ListView) findViewById(R.id.llList); 

     btn1.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       lv1.setVisibility(View.VISIBLE); 

       RelativeLayout.LayoutParams head1Params = new RelativeLayout.LayoutParams(
         LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); 
       head1Params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
       btn2.setLayoutParams(head1Params); 
      } 
     }); 

    } 
} 

和使用下面的XML:

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

    <Button 
     android:layout_alignParentTop="true" 
     android:id="@+id/Button01" 
     android:layout_width="fill_parent" 
     android:layout_height="40dp" 
     android:background="#ffffff" 
     android:text="Button1" > 
    </Button> 

    <ListView 
     android:id="@+id/llList" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_below="@+id/Button01" > 
    </ListView> 

    <Button 
     android:layout_below="@+id/llList" 
     android:id="@+id/button" 
     android:layout_width="fill_parent" 
     android:layout_height="40dp" 
     android:background="#123456" 
     android:text="Button2" > 
    </Button> 

</RelativeLayout> 
+0

雅其工作... :) – 2012-07-13 19:05:00

+0

谢谢你为我的问题提供我这样的解决方案... – 2012-07-13 19:07:52