以下は、ナビゲーションドロワーを作成するためのコードです。問題は、引き出しが正しく表示されないことです。引き出しはアクティビティの開始からは見えますが、部分的にしか見えず、側面からスライドしたり引いたりしません。 1つの場所に固定されているだけです。ここで何が間違っていますか?ナビゲーション・ドロワーのこのコードはなぜ機能しないのですか?
注:私は
package com.example.nirvan.navigationexample3;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView ls=(ListView)findViewById(R.id.listView);
String[] values=
{"one","two","three","four","five","six","seven","eight"};
ArrayAdapter<String> adapter=new ArrayAdapter(this,
R.layout.item,values);
ls.setAdapter(adapter);
}
}
0 mainActivity.java
styles.xml
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<
android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.nirvan.navigationexample3.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"></LinearLayout>
<
android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/nv"
>
<ListView
android:layout_width="200dp"
android:layout_height="match_parent"
android:id="@+id/listView"></ListView>
</android.support.design.widget.NavigationView>
でNoActionBar
を書き込むことによって、アクションバーを削除しました
item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
</TextView>
あなたの引き出しの 'View'に適切な' layout_gravity'属性がありません。 –