单击图像按钮打开滑块

发布于 2025-01-04 12:17:53 字数 307 浏览 1 评论 0原文

我有一些问题

在此处输入图像描述

这是我的 Android 版本的页脚栏,当我点击 i 时按钮然后滑块栏应该用另一个按钮打开,例如

在此处输入图像描述

我如何在 android 中执行此操作

我已经尝试过一些使用警报对话框工作,但它不起作用

任何人都知道我该怎么做,

任何帮助将不胜感激。

i have some problem

enter image description here

this the footer bar of my android build now when i want that when i click on i button then slider bar should be open with another buttons like

enter image description here

how can i do this in android

i have try some work using alert dialog but its not working

any one have idea how can i do that

any help would be appreciated.

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

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

发布评论

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

评论(2

遥远的绿洲 2025-01-11 12:17:53

执行此类操作的一种方法是拥有一个包含要显示或隐藏的按钮行的布局。然后,您可以使用 OnClickListener 设置按钮单击以显示或隐藏布局。因此,在 Activity 中类似这样的东西可以工作:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button toggleButton = (Button)findViewById(R.id.toggle_button);

    //Set click listener to change the bar visiblity
    toggleButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            LinearLayout bar = (LinearLayout)findViewById(R.id.toggle_bar);
            int visibility = bar.getVisibility();

            //Hide or show the bar according to it's current visibility
            if (visibility == View.VISIBLE) {
                bar.setVisibility(View.GONE);
            } else {
                bar.setVisibility(View.VISIBLE);
            }
        }

    });                   
}

简单的示例布局 main.xml 可能看起来有点像这样:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="50.0dp"
    android:orientation="horizontal" >
    <Button
        android:id="@+id/toggle_button"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Toggle visibility"
    />
    <LinearLayout
        android:id="@+id/toggle_bar"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal" >

        <Button 
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Button1"
        />
        <Button 
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Button2"
        />
        <Button 
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Button2"
        />
    </LinearLayout>
</LinearLayout>

如果您还需要在可见性发生变化时为按钮行设置动画,您可能应该查看 动画资源

One way to do something like this is to have a layout that contains the row of buttons you want to show or hide. You can then use an OnClickListener to set the button clicks to show or hide the layout. So something like this in the Activity could work:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button toggleButton = (Button)findViewById(R.id.toggle_button);

    //Set click listener to change the bar visiblity
    toggleButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            LinearLayout bar = (LinearLayout)findViewById(R.id.toggle_bar);
            int visibility = bar.getVisibility();

            //Hide or show the bar according to it's current visibility
            if (visibility == View.VISIBLE) {
                bar.setVisibility(View.GONE);
            } else {
                bar.setVisibility(View.VISIBLE);
            }
        }

    });                   
}

And the simple example layout main.xml could look a bit like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="50.0dp"
    android:orientation="horizontal" >
    <Button
        android:id="@+id/toggle_button"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Toggle visibility"
    />
    <LinearLayout
        android:id="@+id/toggle_bar"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal" >

        <Button 
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Button1"
        />
        <Button 
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Button2"
        />
        <Button 
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Button2"
        />
    </LinearLayout>
</LinearLayout>

If you also need to animate the button row when the visibility changes, you should probably look into animation resources.

十年九夏 2025-01-11 12:17:53

您首先应该在动画文件夹中有一个slide_right_in.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="100%p" android:toXDelta="0"  android:duration="500" />
</set>

和slide_right_out.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="100%p"  android:duration="500" />
</set>

在您的情况下,您需要左进右出动画,因此您应该根据需要更改上面的代码。
然后在动画对象中加载动画,然后在上面的答案中设置可见性之前启动它:

 Animation slide_right_in = AnimationUtils.loadAnimation(this,  R.anim.slide_right_in);
 toggle_bar.startAnimation(slide_right_in);

you should first have a slide_right_in.xml in your anim folder:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="100%p" android:toXDelta="0"  android:duration="500" />
</set>

and slide_right_out.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="100%p"  android:duration="500" />
</set>

in your case you need left in and out animation so you should change above code as per need.
and then load animation in a animation object, then start it just before of setting visibility in above answer:

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