android 将按钮发送到布局的后面

6l7fqoea  于 2023-05-12  发布在  Android
关注(0)|答案(1)|浏览(123)

我试图添加列表会话头,并在后面添加隐藏按钮。
请帮助我发送删除按钮和编辑按钮到会话头的后面。它将在滑动后查看。
我还尝试了bringToFront和sendToBack按钮,但这些按钮都不起作用。
要设置Z顺序,我需要将Project min SDK设置为21,这是我不想做的。所以我也不能使用Z命令。

RelativeLayout SupRelLyoVar = new RelativeLayout(KxtVar);
 RelativeLayout.LayoutParams NamLysHtrRloRulVaj = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, LyHtrHytVal);
 SupRelLyoVar.setLayoutParams(NamLysHtrRloRulVaj);

 Button DelBtnVav = new Button(KxtVar);
 DelBtnVav.setId(View.generateViewId());
 RelativeLayout.LayoutParams DelBtnRulVaj = new RelativeLayout.LayoutParams(LyHtrHytVal, LyHtrHytVal);
 DelBtnRulVaj.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
 DelBtnVav.setLayoutParams(DelBtnRulVaj);
 SupRelLyoVar.addView(DelBtnVav);

 Button EdtBtnVav = new Button(KxtVar);
 RelativeLayout.LayoutParams EdtBtnRulVaj = new RelativeLayout.LayoutParams(LyHtrHytVal, LyHtrHytVal);
 EdtBtnRulVaj.addRule(RelativeLayout.LEFT_OF, DelBtnVav.getId());
 EdtBtnVav.setLayoutParams(EdtBtnRulVaj);
 SupRelLyoVar.addView(EdtBtnVav);

 LinearLayout LnrLyoVar = new LinearLayout(KxtVar);
 LnrLyoVar.setBackgroundColor(SsnHtrBgdClr);
 RelativeLayout.LayoutParams LnrLyoRulVaj = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, LyHtrHytVal);
 LnrLyoRulVaj.addRule(RelativeLayout.CENTER_IN_PARENT);

 TextView TxtVyuVav = new TextView(KxtVar);
 LinearLayout.LayoutParams LysHtrTxtVyuRulVaj = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
 TxtVyuVav.setLayoutParams(LysHtrTxtVyuRulVaj);
 LnrLyoVar.addView(TxtVyuVav);

 SupRelLyoVar.addView(LnrLyoVar, LnrLyoRulVaj);

brqmpdu1

brqmpdu11#

我得到了解决方案,并喜欢张贴
这是为了所有我不想像我一样挣扎的人。
|*| 设置OnTouchListener:

LnrLyoVar.setOnTouchListener(WkaMovLitRitVyuKlkVaf);

|*| 使用以下外部功能:

View.OnTouchListener WkaMovLitRitVyuKlkVaf = new View.OnTouchListener()
{
    float WkaStrVyuXcoVar, WkaStrTchXcoVar, WkaStpTchXcoVar;
    final int MovDstVar = LloHytVal * 2;
    RelativeLayout.LayoutParams EdtBtnRulVaj, DelBtnRulVaj;

    @Override
    public boolean onTouch(View VyuPsgVar, MotionEvent MsnEvtPsgVar)
    {
        switch (MsnEvtPsgVar.getActionMasked())
        {
            case MotionEvent.ACTION_DOWN:
                WkaStrTchXcoVar = MsnEvtPsgVar.getRawX();
                WkaStrVyuXcoVar = (int) VyuPsgVar.getX();
                break;

            case MotionEvent.ACTION_MOVE:
                WkaStpTchXcoVar = MsnEvtPsgVar.getRawX();
                float XcoDstVar = Math.abs(WkaStpTchXcoVar - WkaStrTchXcoVar);

                if (XcoDstVar < MovDstVar)
                {
                    EdtBtnRulVaj = (RelativeLayout.LayoutParams) NamEdtBtnVav.getLayoutParams();
                    DelBtnRulVaj = (RelativeLayout.LayoutParams) NamDelBtnVav.getLayoutParams();
                    int SetBtnWytVar;
                    if (WkaStrVyuXcoVar == 0)
                    {
                        VyuPsgVar.animate()
                                .translationX(-XcoDstVar)
                                .setDuration(0)
                                .start();
                        SetBtnWytVar = (int) XcoDstVar / 2;
                    }
                    else
                    {
                        VyuPsgVar.animate()
                                .x(-MovDstVar + XcoDstVar)
                                .setDuration(0)
                                .start();
                        SetBtnWytVar = (int) (LloHytVal - XcoDstVar / 2);
                    }
                    DelBtnRulVaj.width = SetBtnWytVar;
                    EdtBtnRulVaj.width = SetBtnWytVar;
                    NamEdtBtnVav.setLayoutParams(EdtBtnRulVaj);
                    NamDelBtnVav.setLayoutParams(DelBtnRulVaj);
                }
                break;

            case MotionEvent.ACTION_UP :
            case MotionEvent.ACTION_CANCEL:
                EdtBtnRulVaj = (RelativeLayout.LayoutParams) NamEdtBtnVav.getLayoutParams();
                DelBtnRulVaj = (RelativeLayout.LayoutParams) NamDelBtnVav.getLayoutParams();
                int SetBtnWytVar = 0;
                if (WkaStrVyuXcoVar == 0 && WkaStpTchXcoVar < WkaStrTchXcoVar)
                {
                    VyuPsgVar.animate()
                            .x(-MovDstVar);
                    SetBtnWytVar = LloHytVal;
                }
                else if (WkaStrVyuXcoVar == -MovDstVar)
                {
                    VyuPsgVar.animate()
                            .x(0);
                    SetBtnWytVar = 0;
                }
                DelBtnRulVaj.width = SetBtnWytVar;
                EdtBtnRulVaj.width = SetBtnWytVar;
                NamEdtBtnVav.setLayoutParams(EdtBtnRulVaj);
                NamDelBtnVav.setLayoutParams(DelBtnRulVaj);
                break;
        }
        return true;
    }
};

相关问题