Android:如何使布局基础坚持到底部

时间:2014-07-01 11:04:00

标签: android xml android-layout layout drawer

我在一个文件中有两个布局,一个是隐藏的,只应在单击一个按钮时出现。我使用了动画,但我似乎无法将隐藏的布局粘在主视图的底部。有帮助吗?这些是代码

activity_main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/blue"
tools:context=".MainActivity" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#eeeeee" 
    android:orientation="vertical" >

    <RelativeLayout
        android:id="@+id/action_bar"
        android:layout_width="fill_parent"
        android:layout_height="60dp"
        android:background="@color/blue" >

        <ImageButton
            android:id="@+id/qpaper_menu"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:background="@drawable/menu_button_blue" />

        <TextView
            android:id="@+id/app_header_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@+id/qpaper_menu"
            android:text="UMAR MASH"
            android:textColor="#fff"
            android:textSize="18sp" />
    </RelativeLayout>

   <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="200dp"
        android:layout_margin="12dp"
        android:background="@drawable/bg_card"
        android:orientation="vertical" >

       <TextView 
           android:id="@+id/name"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="Umar mash was ere...."
           android:layout_alignParentLeft="true"/>

       <Button 
           android:id="@+id/slider"
           android:layout_below="@id/name"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="Sleider"
           android:onClick="slider"/>

    </RelativeLayout>

</LinearLayout>

<LinearLayout
android:id="@+id/hidden_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone"
android:background="#000000" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test" />

main_activity.java

    package com.example.kkn;

import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageButton;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener{
    ActionBar ab;
    ImageButton side;
    boolean isPanelDown;
    View hiddenpanel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        side = (ImageButton) findViewById(R.id.qpaper_menu);
        hiddenpanel = findViewById(R.id.hidden_panel);
        ab = getActionBar();
        ab.hide();
        side.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
        case R.id.qpaper_menu:
            Toast.makeText(getApplicationContext(), "This is the menu button", Toast.LENGTH_SHORT).show();
            break;

        default:
            break;
        }
    }

    public void slider(final View view) {
        if (!isPanelShown()) {
            // Show the panel
            Animation bottomUp = AnimationUtils.loadAnimation(this,R.anim.bottom_up);

            hiddenpanel.startAnimation(bottomUp);
            hiddenpanel.setVisibility(View.VISIBLE);
        }
        else {
            // Hide the Panel
            Animation bottomDown = AnimationUtils.loadAnimation(this,R.anim.bottom_down);

            hiddenpanel.startAnimation(bottomDown);
            hiddenpanel.setVisibility(View.GONE);
        }
    }

    private boolean isPanelShown() {
        return hiddenpanel.getVisibility() == View.VISIBLE;
    }
}

buttom_up.xml

    <?xml version="1.0" encoding="utf-8"?>
 <set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate 
       android:fromYDelta="100%p"
       android:toYDelta="30%p"
       android:fillAfter="true"
       android:duration="500" />
</set>

bottom_down.xml

<?xml version="1.0" encoding="utf-8"?>
 <set xmlns:android="http://schemas.android.com/apk/res/android">
<translate 
    android:fromYDelta="0%p" 
    android:toYDelta="100%p" 
    android:fillAfter="true"
    android:interpolator="@android:anim/linear_interpolator"
    android:duration="500" />
</set>

我想要实现的就是这样的

achive

1 个答案:

答案 0 :(得分:0)

请尝试这种方式,希望这有助于您解决问题。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/blue"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#eeeeee"
        android:orientation="vertical" >

        <RelativeLayout
            android:id="@+id/action_bar"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:background="@color/blue" >

            <ImageButton
                android:id="@+id/qpaper_menu"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:background="@drawable/menu_button_blue" />

            <TextView
                android:id="@+id/app_header_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_toRightOf="@id/qpaper_menu"
                android:text="UMAR MASH"
                android:textColor="#fff"
                android:textSize="18sp" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:layout_margin="12dp"
            android:background="@drawable/bg_card"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Umar mash was ere...."
                android:layout_alignParentLeft="true"/>

            <Button
                android:id="@+id/slider"
                android:layout_below="@id/name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Sleider"
                android:onClick="slider"/>

        </RelativeLayout>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/hidden_panel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:visibility="gone"
        android:background="#000000" >
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Test" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Test" />
    </LinearLayout>
</LinearLayout>