1

Как сделать так, чтобы ListView был внизу тулбара, а не так криво как на пикче? И еще вопрос, как убрать эти полоски между элементами ListView? введите сюда описание изображения

Вот xml файл main activity.

<?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <ListView
        android:id="@+id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:dividerHeight="1dp"
        android:listSelector="@drawable/list_row_selector"
        />



    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />


</android.support.v4.widget.DrawerLayout>

Вот код метода onCreate в MainActivity

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    ListViewAdapter adapter = new ListViewAdapter(this);

    ListView lvMain = (ListView) findViewById(R.id.list);
    lvMain.setAdapter(adapter);
}

1 ответ 1

7
  1. У DrawerLayout должно быть только два ребёнка:

    • Основной контент
    • Левое меню

У вас же их три. Так что вам надо объединить первые два в один. Например оберните их в LinearLayout

  1. Линии меж элементами списка это divider. Убрать их можно... убрав их:

    android:divider="@null" 
    

    и вот эту строку тоже надо убрать: android:dividerHeight="1dp". Или 0 прописать

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.