0

我正在尝试添加列表会话标题并在后面添加隐藏按钮。

请帮助我将 Del Button 和 Edit Button 发送到会话标题的后面。滑动后即可查看。

我还尝试了用力起作用的按钮上的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);

在此处输入图像描述

4

1 回答 1

0

我得到了解决方案并喜欢发布
这适用于所有我不想像我一样挣扎的人。

|*| 设置 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;
    }
};
于 2017-06-06T18:32:25.913 回答