简体   繁体   English

将布局放在底部并添加滚动条

[英]Put Layout at bottom and add scrollbar

I have three Relative layouts in may app, on above another. 我的May应用程序中有三个相对布局,在另一个之上。

<RelativeLayout_1><CheckBox></CheckBox></RelativeLayout>
<RelativeLayout_2></RelativeLayout>
<RelativeLayout_3></RelativeLayout>

First is at top, and third is at bottom. 首先是顶部,第三是底部。 When I click on check box in my first layout, second layout is visible/unvisible. 当我单击第一个布局中的复选框时,第二个布局可见/不可见。 How to achive that I always see third layout at bottom and put scrollbar at second when is visible ? 如何使我始终在底部看到第三个布局,并在可见时将滚动条放在第二个? ( Second have lot off content so when is visible, third layout is vanished ). (第二个内容很多,所以当可见时,第三个布局消失了)。

Try 尝试

<?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:orientation="vertical"
   android:background="#888888"
   android:id="@+id/relativeLayout1">
   <RelativeLayout
      android:layout_height="wrap_content"
      android:id="@+id/relativeLayout2"
      android:layout_width="fill_parent"
      android:background="#404000"
      android:layout_alignParentTop="true">
      <CheckBox
         android:text="CheckBox"
         android:id="@+id/checkBox1"
         android:layout_width="wrap_content"
         android:onClick="myClickHandler"
         android:layout_height="wrap_content"></CheckBox>
      <CheckBox
         android:text="CheckBox"
         android:layout_height="wrap_content"
         android:id="@+id/checkBox2"
         android:onClick="myClickHandler"
         android:layout_alignParentRight="true"
         android:layout_width="wrap_content"></CheckBox>
   </RelativeLayout>
   <ScrollView
      android:id="@+id/scrollView1"
      android:layout_below="@+id/relativeLayout2"
      android:scrollbars="vertical"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content">
      <RelativeLayout
         android:layout_height="wrap_content"
         android:id="@+id/relativeLayout3"
         android:layout_width="fill_parent"
         android:background="#000040"
         android:orientation="vertical">
         <TextView
            android:layout_height="190dp"
            android:id="@+id/textView1"
            android:text="TextView1"
            android:layout_alignParentTop="true"
            android:background="#004000"
            android:layout_width="wrap_content"
            android:textSize="20pt"></TextView>
         <TextView
            android:layout_height="190dp"
            android:id="@+id/textView2"
            android:text="TextView2"
            android:layout_width="wrap_content"
            android:background="#000040"
            android:layout_below="@+id/textView1"
            android:textSize="20pt"></TextView>
         <TextView
            android:layout_height="190dp"
            android:id="@+id/textView3"
            android:text="TextView3"
            android:layout_width="wrap_content"
            android:background="#400000"
            android:layout_below="@+id/textView2"
            android:textSize="20pt"></TextView>
      </RelativeLayout>
   </ScrollView>
   <RelativeLayout
      android:layout_height="wrap_content"
      android:id="@+id/relativeLayout4"
      android:layout_width="fill_parent"
      android:layout_alignParentBottom="true">
      <TextView
         android:layout_height="wrap_content"
         android:id="@+id/textView4"
         android:text="I'm a text view in bottom Rel Layout"
         android:layout_alignParentTop="true"
         android:layout_width="wrap_content"
         android:background="#000000"></TextView>
   </RelativeLayout>
</RelativeLayout>

And for the click handler 对于点击处理程序

public void myClickHandler(View target) {

   View rv = findViewById(R.id.scrollView1);
   CheckBox cb1 = (CheckBox) findViewById(R.id.checkBox1);
   CheckBox  cb2 = (CheckBox) findViewById(R.id.checkBox2);

   switch (target.getId()) {
      case R.id.checkBox1:
         cb2.setChecked(false);
         break;
      case R.id.checkBox2:
         cb1.setChecked(false);
         break;
   }
   rv.setVisibility(cb1.isChecked() ? View.VISIBLE : View.GONE);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM