<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="com.example.testandroid.MainActivity" >
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="60dip"
android:layout_marginTop="60dip"
android:visibility="gone"
android:orientation="horizontal" >
<TextView
android:id="@+id/tv1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#936"
android:gravity="center"
android:text="功能1"
android:textColor="#fff"
android:textSize="20dip" />
<TextView
android:id="@+id/tv2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#693"
android:gravity="center"
android:text="功能2"
android:textColor="#fff"
android:textSize="20dip" />
</LinearLayout>
<TextView
android:id="@+id/tv_title"
android:layout_width="fill_parent"
android:layout_height="60dip"
android:background="#369"
android:gravity="center"
android:text="点击标题"
android:textColor="#fff"
android:textSize="20dip" />
</RelativeLayout>
package com.example.testandroid;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.TranslateAnimation;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
TextView tv_title;
LinearLayout layout;
TextView tv1, tv2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
layout = (LinearLayout) findViewById(R.id.linearLayout);
tv_title = (TextView) findViewById(R.id.tv_title);
tv1 = (TextView) findViewById(R.id.tv1);
tv2 = (TextView) findViewById(R.id.tv2);
tv_title.setOnClickListener(onClickListener);
tv1.setOnClickListener(onClickListener);
tv2.setOnClickListener(onClickListener);
}
OnClickListener onClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
if (v == tv1) {
Toast.makeText(MainActivity.this, "功能1", 0).show();
layout.setVisibility(View.GONE);
} else if (v == tv2) {
Toast.makeText(MainActivity.this, "功能2", 0).show();
layout.setVisibility(View.GONE);
} else if (v == tv_title) {
showMenu();
}
}
};
private void showMenu() {
TranslateAnimation translateAnimation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f,
Animation.RELATIVE_TO_SELF, -1f, Animation.RELATIVE_TO_SELF, 0f);
translateAnimation.setDuration(200);
layout.setVisibility(View.VISIBLE);
layout.startAnimation(translateAnimation);
}
}