我有一个按钮,listview和另一个按钮。最初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;
}
}
}
答案 0 :(得分: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>