小按钮

主布局

<LinearLayout
            android:layout_width="0dp"
            android:layout_weight="4"
            android:layout_height="match_parent">
            <View
                android:paddingBottom="5dp"
                android:layout_width="0dp"
                android:layout_weight="3"
                android:layout_height="match_parent"/>
            <ImageView
                android:id="@+id/d_image"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="40dp"
                android:src="@drawable/jiahao"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="16dp"
                android:layout_gravity="center_vertical" />
        </LinearLayout>

代码

         hotAdapter.setOnItemClickListener(new HotAdapter.OnItemClickListener() {
                            @Override
             //点击事件    public void onItemClick(View view, int position) {
                                //Toast.makeText(getActivity(),"12"+"--"+position,Toast.LENGTH_SHORT).show();
                                image = view.findViewById(R.id.d_image);
                                image.setImageResource(R.drawable.breduce);
                                //弹框
                                showPopupWindow(view);

                            }
                            private void showPopupWindow(final View vvv) {
                                View contentView = LayoutInflater.from(getActivity()).inflate(R.layout.photo_popup_layout, null);
                                mPopWindow = new PopupWindow(contentView,
                                        ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
                                mPopWindow.setContentView(contentView);
                                mPopWindow.setBackgroundDrawable(new BitmapDrawable());
                                mPopWindow.setOutsideTouchable(true);
                                mPopWindow.setAnimationStyle(R.style.AnimationPreview);
                                ColorDrawable dw = new ColorDrawable(0000000000);
                                mPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
                                    @Override
                                    public void onDismiss() {
                                        ImageView image = vvv.findViewById(R.id.d_image);

                                        image.setImageResource(R.drawable.badd);
                                    }
                                });

                                contentView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
                                int  mShowMorePopupWindowWidth = -contentView.getMeasuredWidth();
                                int  mShowMorePopupWindowHeight = -contentView.getMeasuredHeight();
                                mPopWindow.showAsDropDown(vvv,mShowMorePopupWindowWidth, mShowMorePopupWindowHeight);

                            }
                        });

布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:padding="6dp"
    android:orientation="horizontal"
    android:layout_height="match_parent">
<ImageView
    android:id="@+id/image_01"
    android:padding="4dp"
    android:layout_gravity="center"
    android:layout_marginLeft="10dp"
    android:src="@drawable/tmess"
    android:background="@drawable/blue_cirl"
    android:layout_width="30dp"
    android:layout_height="30dp" />
    <ImageView
        android:layout_gravity="center"
        android:padding="4dp"
        android:layout_marginLeft="10dp"
        android:background="@drawable/blue_cirl"
        android:src="@drawable/tshar"
        android:layout_width="30dp"
        android:layout_height="30dp" />
    <ImageView
        android:padding="4dp"
        android:layout_gravity="center"
        android:layout_marginLeft="10dp"
        android:background="@drawable/blue_cirl"
        android:src="@drawable/thart"
        android:layout_width="30dp"
        android:layout_height="30dp" />
</LinearLayout>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
QStackedWidget是Qt中的一个容器类,用于管理多个嵌套小部件(QWidgets)的堆栈。小按钮用于切换显示不同的小部件。要实现翻页功能,可以使用QStackedWidget的setCurrentIndex()函数来指定当前显示的小部件的索引。 首先,在QStackedWidget中添加多个小部件,每个小部件代表一个页面。可以使用addWidget()函数将小部件添加到QStackedWidget中。 然后,创建一个用于翻页的按钮,并连接按钮的clicked信号到一个槽函数。在槽函数中,通过调用QStackedWidget的currentIndex()函数获取当前显示的小部件的索引。然后,根据需要翻页的方向(向前或向后),使用setCurrentIndex()函数将当前显示的小部件索引加上或减去1,并设置为新的当前索引。 以下是一个简单示例代码: ```cpp #include <QtWidgets> int main(int argc, char *argv[]) { QApplication app(argc, argv); QStackedWidget stackedWidget; // 添加小部件 QWidget *page1 = new QWidget; QWidget *page2 = new QWidget; stackedWidget.addWidget(page1); stackedWidget.addWidget(page2); // 创建按钮 QPushButton *prevButton = new QPushButton("上一页"); QPushButton *nextButton = new QPushButton("下一页"); // 连接按钮的clicked信号到槽函数 QObject::connect(prevButton, &QPushButton::clicked, [&stackedWidget]() { // 向前翻页 int currentIndex = stackedWidget.currentIndex(); stackedWidget.setCurrentIndex(currentIndex - 1); }); QObject::connect(nextButton, &QPushButton::clicked, [&stackedWidget]() { // 向后翻页 int currentIndex = stackedWidget.currentIndex(); stackedWidget.setCurrentIndex(currentIndex + 1); }); // 创建布局,并添加小部件和按钮 QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(&stackedWidget); layout->addWidget(prevButton); layout->addWidget(nextButton); // 设置布局 QWidget window; window.setLayout(layout); window.show(); return app.exec(); } ``` 运行上述代码,会显示一个带有两个页面和上一页/下一页按钮的窗口。点击按钮时,会切换显示不同的页面。其中,QStackedWidget的setCurrentIndex()函数用于翻页。上一页按钮会将当前索引减1,并将新的索引设置为当前索引,下一页按钮则将当前索引加1,并将新的索引设置为当前索引。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值