用UC的时候,可选择在右边显示一个透明浮动条来显示翻页。
其实很简单,就是在顶层窗口再加上一个布局就可以了。
浮动条的界面布局,找不到透明的图片。。。
<?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="fill_parent"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:id="@+id/overlay"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/add"
android:id="@+id/imageview_up"
android:padding="5dp"
android:focusable="true"
android:background="@drawable/grid_item_selector"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/del"
android:layout_below="@id/imageview_up"
android:id="@+id/imageview_down"
android:padding="5dp"
android:background="@drawable/grid_item_selector"
/>
</LinearLayout>
</RelativeLayout>
主程序,其实就是通过得到顶层的view,再将上面的viewgroup加入即可
public class MainActivity extends Activity implements View.OnClickListener{
RelativeLayout overlay;
boolean overlayIsVisibility = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initOverlay();
findViewById(R.id.showOverlayButton).setOnClickListener(this);
findViewById(R.id.hideOverlayButton).setOnClickListener(this);
}
private void initOverlay() {
//如果该acitivity是嵌入的,此处还需要判断
ViewGroup viewGroup = (ViewGroup) getWindow().getDecorView();
overlay = (RelativeLayout) LayoutInflater.from(this).inflate(R.layout.other, null);
View imageViewUp = overlay.findViewById(R.id.imageview_up);
imageViewUp.setOnClickListener(this);
View imageViewDown = overlay.findViewById(R.id.imageview_down);
imageViewDown.setOnClickListener(this);
viewGroup.addView(overlay);
overlay.setVisibility(View.GONE);
overlayIsVisibility = false;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.imageview_up:
Toast.makeText(this, "up", 1000).show();
break;
case R.id.imageview_down:
Toast.makeText(this, "down", 1000).show();
break;
case R.id.showOverlayButton:
if(!overlayIsVisibility) {
overlay.setVisibility(View.VISIBLE);
overlayIsVisibility = true;
}
break;
case R.id.hideOverlayButton:
if(overlayIsVisibility) {
overlay.setVisibility(View.GONE);
overlayIsVisibility = false;
}
break;
}
}
}
还有要注意一点:当要在当前窗口上面,覆盖透明的一层时,常需要复写onkey方法,使back按钮从透明界面跳到原界面,或从原界面跳出。