开发者

For designing dynamic layout in android like the status bar in the home screen

开发者 https://www.devze.com 2023-04-04 23:49 出处:网络
How to make a layout in android like the s开发者_JS百科tatus bar in the home screen which allows the user to drag the status bar up to any height. The layout should also allow the user with a flick up

How to make a layout in android like the s开发者_JS百科tatus bar in the home screen which allows the user to drag the status bar up to any height. The layout should also allow the user with a flick up or down to expand or contract the the layout fully.


Do you mean something like a SlidingDrawer?

For designing dynamic layout in android like the status bar in the home screen

For designing dynamic layout in android like the status bar in the home screen

Can be used like this:

/src - SliderActivity.java:

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.SlidingDrawer;
import android.widget.SlidingDrawer.OnDrawerCloseListener;
import android.widget.SlidingDrawer.OnDrawerOpenListener;

public class SliderActivity extends Activity {
    Button slideHandleButton;
    SlidingDrawer slidingDrawer;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);
        slideHandleButton = (Button) findViewById(R.id.slideHandleButton);
        slidingDrawer = (SlidingDrawer) findViewById(R.id.SlidingDrawer);

        slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
            @Override
            public void onDrawerOpened() {
                slideHandleButton.setBackgroundResource(R.drawable.arrowdown);
            }
        });

        slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {
            @Override
            public void onDrawerClosed() {
                slideHandleButton.setBackgroundResource(R.drawable.arrowup);
            }
        });
    }
}

/res/layout - main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:gravity="bottom">
    <SlidingDrawer android:layout_width="wrap_content"
        android:id="@+id/SlidingDrawer" android:handle="@+id/slideHandleButton"
        android:content="@+id/contentLayout" android:padding="10dip"
        android:layout_height="200dip">
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:id="@+id/slideHandleButton"
            android:background="@drawable/arrowup"></Button>
        <LinearLayout android:layout_width="wrap_content"
            android:id="@+id/contentLayout" android:orientation="vertical"
            android:gravity="center|top" android:padding="10dip"
            android:background="#505050" android:layout_height="wrap_content">
            <TextView android:id="@+id/TextView01" android:layout_width="wrap_content"
                android:layout_height="fill_parent" android:layout_weight="8" android:text="Hello Slider"></TextView>
            <Button android:id="@+id/Button02" android:layout_weight="2" android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:text="Do anything"></Button>
        </LinearLayout>
    </SlidingDrawer>
</LinearLayout>

You need 2 images in your /res/drawable folder to make it work, like arrowup.png and arrowdown.png in this example

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号