从右侧制作我的导航列表



我有一个包含导航列表的活动,它从左侧滑动并且它正在工作,但我希望列表位于右侧。

我试图从我的xml文件中更改gravity_layout,但应用程序崩溃了。

package com.parse.starter;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import com.parse.ParseUser;
public class UserDrawer extends AppCompatActivity {
//Declaring Variables
private ListView DrawerList;
private ArrayAdapter<String> Adapter;
private ActionBarDrawerToggle DrawerToggle;
private DrawerLayout DrawerLayout;
private String ActivityTitle;

final ParseUser currentUser = ParseUser.getCurrentUser();
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_user_drawer);
    DrawerList = (ListView) findViewById(R.id.navList);
    DrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActivityTitle = getTitle().toString();
    addDrawerItems();
    setupDrawer();
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    Button Sample = (Button) findViewById(R.id.button);
}
//Method To Add Items To The List View
private void addDrawerItems() {
    String[] DArray = {"Job List", "Notifications", "Messages", "Log Out"};
    Adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, DArray);
    DrawerList.setAdapter(Adapter);
    DrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0) {
                Intent i0 = new Intent(UserDrawer.this, Set_Info.class);
                startActivity(i0);
            } else if (position == 1) {
                //Intent i1 = new Intent(Drawer1.this, AddPatient.class);
                //startActivity(i1);
            } else if (position == 2) {
                //Intent i2 = new Intent(Drawer1.this, Notifications.class);
                //startActivity(i2);
            } else if (position == 3) {
                //Intent i3 = new Intent(Drawer1.this, Message_Log.class);
                //startActivity(i3);
            } else if (position == 4) {
                Intent i4 = new Intent(UserDrawer.this, MainActivity.class);
                startActivity(i4);
                Toast.makeText(getApplicationContext(), "You are Logged Out", Toast.LENGTH_LONG).show();
                finish();
            }
        }
    });
}
private void setupDrawer() {
    DrawerToggle = new ActionBarDrawerToggle(this, DrawerLayout,
            R.string.drawer_open, R.string.drawer_close) {
        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            getSupportActionBar().setTitle("Menu");
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            getSupportActionBar().setTitle(ActivityTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    DrawerToggle.setDrawerIndicatorEnabled(true);
    DrawerLayout.setDrawerListener(DrawerToggle);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Activate the navigation drawer toggle
    if (DrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    DrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    DrawerToggle.onConfigurationChanged(newConfig);
}
@SuppressWarnings("ResourceType")
public void SampleClick(View view) {
    try {
        Intent i = new Intent(UserDrawer.this,Set_Info.class);
        startActivity(i);
    } catch (Exception e) {
    }
}

}

http://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html

抽屉的位置和布局使用子视图上的 android:layout_gravity 属性进行控制,对应于您希望抽屉从视图的哪一侧出现:左侧或右侧。(或在支持布局方向的平台版本上开始/结束。

即它是android:layout_gravity而不是gravity_layout,它不应该再崩溃。

尝试gravity:Endor Right而不是gravity:Start阅读此答案

相关内容

  • 没有找到相关文章

最新更新