slide ExpandableListView at DrawerLayout form right to left

前端 未结 3 1756
忘了有多久
忘了有多久 2020-12-16 04:18

How to slide ExpandableListView at DrawerLayout form right to left

i want to show ExpandableListView at right corner of screen , how can i do that ??



        
相关标签:
3条回答
  • 2020-12-16 04:29

    Change android:layout_gravity="start" to either android:layout_gravity="end" or android:layout_gravity="right" (using end will put the drawer on the left side of the screen for right-to-left configurations)

    EDIT

    It appears that the ActionBarDrawerToggle is looking for a drawer on the same side as the action bar Home icon (Gravity.START), which would be the left side for left-to-right layout directions. If you will always have the drawer on the right, you could do something like this:

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawer, R.drawable.ic_drawer, R.string.open_drawer, R.string.close_drawer) {
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            if (item != null && item.getItemId() == android.R.id.home) {
                if (mDrawer.isDrawerOpen(Gravity.RIGHT)) {
                    mDrawer.closeDrawer(Gravity.RIGHT);
                } else {
                    mDrawer.openDrawer(Gravity.RIGHT);
                }
            }
            return false;
        }
    };
    

    If the drawer will always be opposite the action bar Home icon, you could use Gravity.END instead.

    0 讨论(0)
  • 2020-12-16 04:50

    I have the same problem since my app is Arabic and must begin from the right.

    After testing all solutions here, I found that the best is:

    • add this line in manifest : android:supportsRtl="true"
    • in your activity add this code : getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
    • in your listview don't use : android:layout_gravity="right" because if you use right you get the error in more Android versions like 4.0.4

    The solution is the use of: android:layout_gravity="start", because in this case the listview follows the gravity of the page.

    0 讨论(0)
  • 2020-12-16 04:53

    It is a bug in the home button click in ActionBar that shows itself in line:

    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }
    

    remove the lines I mentioned, where you have method:

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
       if (mDrawerToggle.onOptionsItemSelected(item)) {
          return true;
       }
       //....
    }
    

    and replace it with:

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        if (item != null && item.getItemId() == android.R.id.home) {
            if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) {
                mDrawerLayout.closeDrawer(Gravity.RIGHT);
            } else {
                mDrawerLayout.openDrawer(Gravity.RIGHT);
            }
            return true;
        }
        //...
    }
    

    Also do not forget to change the gravity of ListView to right: android:layout_gravity="right"

    0 讨论(0)
提交回复
热议问题