-1

我有一个按钮,列表视图和另一个按钮。最初列表视图的属性消失了,所以按钮 2 显示在按钮 1 的下方,当我单击按钮 1 时,按钮 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;
        }

    }
}

在此处输入图像描述

4

1 回答 1

1

Use this Activity code:

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);
            }
        });

    }
}

and Use Following 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>
于 2012-07-13T18:48:40.733 回答