[英]Semi-transparent text box over photo
I'm trying to overlay a semi-transparent text box over a photo for description. 我试图在照片上覆盖一个半透明的文本框以进行描述。 Tapping on the screen should make it slide up/down.
轻击屏幕应使其向上/向下滑动。 It should also contain a rating bar in the bottom.
它还应在底部包含一个等级栏。
Much like in Google Goggles http://blogote.com/wp-content/uploads/2010/10/GoogleGoggles1.jpg 就像在Google Goggles中一样http://blogote.com/wp-content/uploads/2010/10/GoogleGoggles1.jpg
How would you do it? 你会怎么做? This is what I have so far:
这是我到目前为止的内容:
<FrameLayout
android:id="@+id/mainlayout"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:foregroundGravity="bottom"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:id="@+id/imgview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="@string/hello"/>
</FrameLayout>
This can be easily implemented with a RelativeLayout
and a SlidingDrawer
widget. 这可以通过
RelativeLayout
和SlidingDrawer
小部件轻松实现。
RelativeLayout
is required so that you can attach the drawer to the bottom of the layout and have it open over the photo. RelativeLayout
是必需的,以便您可以将抽屉连接到布局的底部,并将其在照片上打开。 SlidingDrawer
widget has 2 required properties: android:handle
and android:content
. SlidingDrawer
小部件具有2个必需的属性: android:handle
和android:content
。 For clean layouts, you'll probably want these as separate layout files. android:background
property as a ARGB (Alpha RGB) value. android:background
属性作为ARGB(Alpha RGB)值传递即可。 Below uses "#BF000000" which is black at roughly 75% opacity. ImageView
and your SlidingDrawer
. ImageView
和SlidingDrawer
。 Just for kicks, here's a full working example... 仅此而已,这是一个完整的工作示例...
Your layout XML: 您的布局XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView android:id="@+id/image"
android:src="@drawable/bunnywaffles"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
/>
<SlidingDrawer android:id="@+id/SlidingDrawer"
android:handle="@+id/slideHandleButton"
android:content="@+id/contentLayout"
android:layout_width="fill_parent"
android:layout_height="150dip"
android:layout_alignParentBottom="true" >
<Button android:id="@+id/slideHandleButton"
android:layout_width="0dip"
android:layout_height="0dip"
android:visibility="gone"
/>
<LinearLayout android:id="@+id/contentLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:background="#BF000000">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
<Button android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1"
/>
<Button android:id="@+id/Button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button2"
/>
</LinearLayout>
<RatingBar android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5" />
</LinearLayout>
</SlidingDrawer>
</RelativeLayout>
And your activity Java: 而您的活动Java:
ImageView _image;
SlidingDrawer _drawer;
Boolean _drawerOpen = false;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
_image = (ImageView) findViewById( R.id.image );
_image.setOnClickListener(ToggleDrawer);
_drawer = (SlidingDrawer) findViewById( R.id.SlidingDrawer );
_drawer.setOnClickListener(ToggleDrawer);
}
private View.OnClickListener ToggleDrawer = new View.OnClickListener() {
public void onClick(View view) {
if ( _drawerOpen )
_drawer.animateClose();
else
_drawer.animateOpen();
_drawerOpen = !_drawerOpen;
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.