用于在 Android 中设计动态布局,例如主屏幕中的状态栏

发布于 2024-12-04 06:58:22 字数 99 浏览 0 评论 0原文

如何在android中制作一个类似于主屏幕中的状态栏的布局,允许用户将状态栏拖动到任意高度。布局还应该允许用户通过向上或向下滑动来完全扩展或收缩布局。

How to make a layout in android like the status 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如果没结果 2024-12-11 06:58:23

您的意思是类似 SlidingDrawer 的东西吗?

替代文本

替代文本

可以这样使用:

/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 - ma​​in.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>

您需要在 /res/drawable 文件夹中放置 2 个图像才能制作它工作,如本例中的 arrowup.pngarrowdown.png

Do you mean something like a SlidingDrawer?

alt text

alt text

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文