PopupWindow组件实现浮动窗口
2014-06-19 21:28
239 查看
1、PopupWindow组件实现的是浮动窗口的功能,该组件需要通过new对象的形式来动态创建。
但创建后也需要设置窗口里面的内容的样式,因此也需要声明其布局文件。
在layout下建立一个文件。
<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="#000000"
android:orientation="vertical" >
<TextView
android:id="@+id/show_version"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="查看版本"
android:textColor="#ffffff"
android:textSize="14sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#ffffff" />
<TextView
android:id="@+id/about_auth"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="关于作者"
android:textColor="#ffffff"
android:textSize="14sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#ffffff" />
<TextView
android:id="@+id/exit"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="退出"
android:textColor="#ffffff"
android:textSize="14sp" />
</LinearLayout>
显示浮动窗口时,需要设置其大小。
2、评分组件
通过RatingBar评分组件,可以实现打分功能的显示。
但创建后也需要设置窗口里面的内容的样式,因此也需要声明其布局文件。
在layout下建立一个文件。
<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="#000000"
android:orientation="vertical" >
<TextView
android:id="@+id/show_version"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="查看版本"
android:textColor="#ffffff"
android:textSize="14sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#ffffff" />
<TextView
android:id="@+id/about_auth"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="关于作者"
android:textColor="#ffffff"
android:textSize="14sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#ffffff" />
<TextView
android:id="@+id/exit"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="退出"
android:textColor="#ffffff"
android:textSize="14sp" />
</LinearLayout>
显示浮动窗口时,需要设置其大小。
settingBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { if (win == null) { win = new PopupWindow(Globals.SCREEN_WIDTH / 4, Globals.SCREEN_HEIGHT / 6); View v = LayoutInflater.from(BaseActivity.this).inflate( R.layout.window_layout, null); // 设置其布局 win.setContentView(v); // 加入这些内部按钮的监听 // 分别取得这些组件 TextView versionText = (TextView) v .findViewById(R.id.show_version); TextView authText = (TextView) v .findViewById(R.id.about_auth); TextView exitText = (TextView) v.findViewById(R.id.exit); versionText.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(BaseActivity.this, "当前版本是: 1.0", Toast.LENGTH_LONG).show(); win.dismiss(); } }); authText.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Builder builder = new Builder(BaseActivity.this); builder.setTitle("提示"); builder.setMessage("本作品由北航发布, 欢迎使用!"); builder.setPositiveButton("关闭", new DialogInterface.OnClickListener() { @Override public void onClick( DialogInterface dialog, int which) { } }); builder.create().show(); win.dismiss(); } }); exitText.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // 退出程序 } }); } if (win.isShowing()) { // 隐藏 win.dismiss(); } else { // 显示 win.showAsDropDown(settingBtn); } } });
2、评分组件
通过RatingBar评分组件,可以实现打分功能的显示。
<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:orientation="vertical" > <RatingBar android:id="@+id/rating" android:layout_width="wrap_content" android:layout_height="wrap_content" android:numStars="5" android:rating="3" android:stepSize="0.5" /> </LinearLayout>
public class MainActivity extends Activity { private RatingBar rating; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 设置默认使用的布局文件 setContentView(R.layout.activity_main); rating = (RatingBar) findViewById(R.id.rating); rating.setOnRatingBarChangeListener(new OnRatingBarChangeListener() { @Override public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { Toast.makeText(MainActivity.this, "得分: " + rating, Toast.LENGTH_SHORT).show(); } }); } }
相关文章推荐
- 【Vegas原创】使用GreyBox组件实现ajax弹出式窗口效果
- 类似flashget的浮动窗口的实现
- C#浮动的窗口如何实现
- android弹出窗口的实现(PopupWindow)
- 用JS实现网页浮动窗口随窗口滚动(类似于客服窗口)
- 看到一网站,他的浮动广告可以浮动到所有窗口的上面,实现原码在这里
- jQuery之浮动窗口实现代码(两种方法)
- 类似flashget的浮动窗口的实现
- popupwindow 如何实现弹出菜单效果_popupwindow 实现弹出窗口范例
- javascript 实现WINDOWS 风格的可拖拽的DIV浮动窗口
- 如何在页面上动态实现浮动窗口?
- JQuery实现的页面滚动时浮动窗口控件
- 半透明信息显示浮动窗口的实现
- DXUTBlendColor::Blend()实现DirectX3D窗口GUI动态组件的分析研究(多图)
- 类似flashget的浮动窗口的实现
- JQuery 实现的页面滚动时浮动窗口控件
- js代码实现浮动窗口的功能.
- 用JS实现网页浮动窗口随窗口滚动(类似于客服窗口)
- 网页中实现浮动客服窗口
- android弹出窗口的实现(PopupWindow)