Android 侧拉选择框

来源:互联网 发布:大数据关键技术 云计算 编辑:程序博客网 时间:2024/05/17 12:55

      效果如图所示:当点击Hello World!的时候,会从右侧出现右侧显示框。点击右侧的白色区域,右侧显示框会隐藏掉。

布局文件的代码:

<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"    tools:context=".MainActivity" >    <TextView android:id="@+id/tv"        android:layout_width="70dp"        android:layout_height="70dp"        android:text="@string/hello_world"        android:gravity="center"        android:layout_centerInParent="true" />    <LinearLayout android:id="@+id/ll"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:visibility="visible" >                <LinearLayout            android:id="@+id/ll_1"            android:layout_width="0dp"            android:layout_height="fill_parent"            android:layout_weight="1"            android:background="#ffffff"            android:orientation="vertical">        </LinearLayout>        <LinearLayout             android:layout_width="0dp"            android:layout_height="fill_parent"            android:layout_weight="2"            android:background="#043E39"            android:orientation="vertical">        </LinearLayout>    </LinearLayout></RelativeLayout>
主界Activity的代码:

package com.example.andemo;import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.view.animation.Animation;import android.view.animation.TranslateAnimation;public class MainActivity extends Activity implements OnClickListener{TranslateAnimation showAnim;TranslateAnimation HiddenAnim;private View ll;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);ll = findViewById(R.id.ll);//显示的动画showAnim=  new TranslateAnimation(Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f);//隐藏的动画HiddenAnim=  new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f);//显示过程的时间showAnim.setDuration(400);//隐藏过程的时间HiddenAnim.setDuration(400);findViewById(R.id.tv).setOnClickListener(this);findViewById(R.id.ll_1).setOnClickListener(this);}@Overridepublic void onClick(View v) {// TODO Auto-generated method stubswitch (v.getId()) {case R.id.tv:ll.startAnimation(showAnim);ll.setVisibility(View.VISIBLE);break;case R.id.ll_1:ll.startAnimation(HiddenAnim);ll.setVisibility(View.GONE);break;default:break;}}}


0 0
原创粉丝点击