本文主要是介绍android Activity实现从右边弹出或滑出选择菜单或窗口,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
android Activity实现从底部弹出或滑出选择菜单或窗口 http://104zz.iteye.com/blog/1685425
一下是android Activity实现从右边弹出或滑出选择菜单或窗口:
main布局:
/SelectPicPopupWindow/res/layout/activity_main.xml
<?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="wrap_content"android:gravity="center_horizontal"android:orientation="vertical"><TextView android:layout_width="match_parent"android:layout_height="wrap_content"android:id="@+id/text"android:text="按我彈窗口"/>
</RelativeLayout>
弹窗口的布局:
/SelectPicPopupWindow/res/layout/alert_dialog.xml
<?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="wrap_content" ><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="horizontal" ><LinearLayoutandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1" ></LinearLayout><LinearLayoutandroid:id="@+id/pop_layout"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:orientation="vertical"android:background="#ffffff" ></LinearLayout></LinearLayout>
</RelativeLayout>
/SelectPicPopupWindow/src/com/lxm/selectpicpopupwindow/SelectPicPopupWindow.java
package com.lxm.selectpicpopupwindow;import java.util.ArrayList;
import java.util.List;import com.lxm.selectpicpopupwindow.been.Items;import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;public class SelectPicPopupWindow extends Activity implements OnClickListener {// private Button btn_take_photo, btn_pick_photo, btn_cancel;
// private LinearLayout layout;
// List<Items> items;
// Items itemss;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.alert_dialog);
// btn_take_photo = (Button) this.findViewById(R.id.btn_take_photo);
// btn_pick_photo = (Button) this.findViewById(R.id.btn_pick_photo);
// btn_cancel = (Button) this.findViewById(R.id.btn_cancel);
// ListView listView = (ListView) findViewById(R.id.listview);
// items = new ArrayList<Items>();
// itemss = new Items();
// for(int i=0;i<2;i++){
//
// itemss.setNo("11");
// itemss.setItem_name("aa");
// itemss.setSearch_time("cc");
// items.add(itemss);
// }
//
// MyAdapter adapter = new MyAdapter(getApplication(),items);
// listView.setAdapter(adapter);
// layout = (LinearLayout) findViewById(R.id.pop_layout);// 添加选择窗口范围监听可以优先获取触点,即不再执行onTouchEvent()函数,点击其他地方时执行onTouchEvent()函数销毁Activity
// layout.setOnClickListener(new OnClickListener() {
//
// public void onClick(View v) {
// // TODO Auto-generated method stub
// Toast.makeText(getApplicationContext(), "提示:点击窗口外部关闭窗口!",
// Toast.LENGTH_SHORT).show();
// }
// });
// // 添加按钮监听
// btn_cancel.setOnClickListener(this);
// btn_pick_photo.setOnClickListener(this);
// btn_take_photo.setOnClickListener(this);}// 实现onTouchEvent触屏函数但点击屏幕时销毁本Activity@Overridepublic boolean onTouchEvent(MotionEvent event) {finish();return true;}
//
// public void onClick(View v) {
// switch (v.getId()) {
// case R.id.btn_take_photo:
// break;
// case R.id.btn_pick_photo:
// break;
// case R.id.btn_cancel:
// break;
// default:
// break;
// }
// finish();
// }@Overridepublic void onClick(View v) {// TODO Auto-generated method stub}}
/SelectPicPopupWindow/src/com/lxm/selectpicpopupwindow/MainActivity.java
package com.lxm.selectpicpopupwindow;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ListView;
import android.widget.TextView;public class MainActivity extends Activity {@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);TextView tv = (TextView) this.findViewById(R.id.text);//把文字控件添加监听,点击弹出自定义窗口tv.setOnClickListener(new OnClickListener() { public void onClick(View v) {startActivity(new Intent(MainActivity.this,SelectPicPopupWindow.class));}});}}
/SelectPicPopupWindow/AndroidManifest.xml
<activity android:name=".SelectPicPopupWindow" android:theme="@style/MyDialogStyleBottom" />
/SelectPicPopupWindow/res/values/styles.xml
<style name="AnimBottom" parent="@android:style/Animation"><item name="android:windowEnterAnimation">@anim/push_bottom_in</item><item name="android:windowExitAnimation">@anim/push_buttom_out</item></style><style name="MyDialogStyleBottom" parent="android:Theme.Holo.DialogWhenLarge"><item name="android:windowAnimationStyle">@style/AnimBottom</item><item name="android:windowFrame">@null</item><!-- 边框 --><!-- <item name="android:windowIsFloating">true</item> --><!-- 是否浮现在activity之上 --><!-- 半透明 --><item name="android:windowIsTranslucent">true</item><!-- 无标题 --><item name="android:windowNoTitle">true</item><!-- 背景透明 --><item name="android:windowBackground">@android:color/transparent</item><!-- 是否允许对话框的背景变暗 --><item name="android:backgroundDimEnabled">true</item></style>
/SelectPicPopupWindow/res/anim/push_bottom_in.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- 右左滑入式 -->
<set xmlns:android="http://schemas.android.com/apk/res/android" ><translateandroid:duration="200"android:fromXDelta="100%p"android:toXDelta="0" />
</set>
/SelectPicPopupWindow/res/anim/push_buttom_out.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- 左右滑出式 -->
<set xmlns:android="http://schemas.android.com/apk/res/android" ><translateandroid:duration="200"android:fromXDelta="0"android:toXDelta="100%p" />
</set>
效果图:
源码下载
这篇关于android Activity实现从右边弹出或滑出选择菜单或窗口的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!