[英]Android: How to make layout Base stick to the bottom
I have 2 layouts in one file, one is hidden and should only appear when a button is clicked. 我在一个文件中有2种布局,一种布局是隐藏的,仅当单击按钮时才应显示。 I used an animation but i cant seem to get the hidden layout to stick to the bottom of the main view.
我使用了动画,但似乎无法将隐藏的布局固定在主视图的底部。 Any help?
有什么帮助吗? these are the codes
这些是代码
Activity_main.xml 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 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 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 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>
All i am trying to achieve is something like this 我想要实现的就是这样
Try this way,hope this will help you to solve your problem. 尝试这种方式,希望这将帮助您解决问题。
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.