SlidingPanelLayout not work well from right to left in android

↘锁芯ラ 提交于 2019-12-01 14:19:52

I think I found the Solution. I am Creating the new Project.

Sliding.java

public class Sliding extends LinearLayout
{
    private Paint innerPaint, borderPaint ;
    public Sliding(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }
    public Sliding(Context context) {
        super(context);
        init();
    }
    private void init() {
        innerPaint = new Paint();
        innerPaint.setARGB(0, 255, 255, 255); //gray
        innerPaint.setAntiAlias(true);
        borderPaint = new Paint();
        borderPaint.setARGB(255, 255, 255, 255);
        borderPaint.setAntiAlias(true);
        borderPaint.setStyle(Paint.Style.STROKE);
        borderPaint.setStrokeWidth(2);
    }
    public void setInnerPaint(Paint innerPaint) {
        this.innerPaint = innerPaint;
    }
    public void setBorderPaint(Paint borderPaint) {
        this.borderPaint = borderPaint;
    }
    @Override
    protected void dispatchDraw(Canvas canvas) {
        RectF drawRect = new RectF();
        drawRect.set(0,0, getMeasuredWidth(), getMeasuredHeight());
        canvas.drawRoundRect(drawRect, 5, 5, innerPaint);
        canvas.drawRoundRect(drawRect, 5, 5, borderPaint);
        super.dispatchDraw(canvas);
    }
}

Sliding2Activity.java

public class Sliding2Activity extends Activity {

    CheckBox c1,c2,c3;
    int key=0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sliding2);

        final Sliding popup = (Sliding) findViewById(R.id.sliding1);
        popup.setVisibility(View.GONE);

        final FloatingActionButton btn=(FloatingActionButton)findViewById(R.id.show1);
        btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                if (key == 0) {
                    key = 1;
                    popup.setVisibility(View.VISIBLE);

                } else if (key == 1) {
                    key = 0;
                    popup.setVisibility(View.GONE);

                }
            }
        });

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_sliding2, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

activity_sliding2.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="fill_parent"
    android:gravity="right"
    android:orientation="horizontal">

    <com.rey.material.widget.FloatingActionButton
        android:id="@+id/show1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        style="@style/LightFABWaveColor"
        android:layout_margin="8dp"
        android:layout_gravity="bottom" />

   <com.example.softeng.panel.Sliding
        android:id="@+id/sliding1"
        android:layout_width="250dp"
        android:layout_height="match_parent"
        android:background="#0072BA"
        android:gravity="left"
        android:orientation="vertical"
        android:padding="1px">

        <CheckBox
            android:id="@+id/check1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Option1"
            android:textColor="#FFFFFF" />

        <CheckBox
            android:id="@+id/check2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Option2"
            android:textColor="#FFFFFF" />

        <CheckBox
            android:id="@+id/check3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Option3"
            android:textColor="#FFFFFF" />
    </com.example.softeng.panel.Sliding>



</LinearLayout>

ScreenShot :

Normal screen when Activity is running.

When Click on FloatinActionButton. The layout is change.

When you click again the output is screen one.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!