Как исправить пространство между FrameLayout - ConstraintLayout - PullRequest
0 голосов
/ 22 декабря 2018

Я пытаюсь реализовать свой макет, но не могу получить правильный макет.Когда мое устройство находится в портретном режиме, и я использую ограничение. Гид, я пытаюсь найти правильный номер, чтобы поместить нижнюю часть ORANGE FrameLayout рядом с BottomNavigationView.Если я использую app: layout_constraintGuide_percent = ". 90" рядом с "правильным" числом, но я думаю, что это неправильно ... также, когда я переводю устройство в альбомный режим, ORANGE FrameLayout исчезает и длявновь появиться я должен установить app: layout_constraintGuide_percent = ". 80" .Я новичок

portrait

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: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"
    android:background="@color/colorMain"
    tools:openDrawer="start">


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

    <!-- The activity_nav_drawer drawer that comes from the left -->
    <!-- Note that `android:layout_gravity` needs to be set to 'start' -->
    <android.support.design.widget.NavigationView
        android:id="@+id/master_fragment_container"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        android:fitsSystemWindows="true"/>
        <!--app:headerLayout="@layout/nav_header_nav"-->
        <!--app:menu="@menu/activity_nav_drawer" />-->

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

app_bar_nav.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.masterdetailexample.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="?android:attr/windowBackground"
        android:foreground="?attr/selectableItemBackground"
        app:itemBackground="@color/bgBottomNavigation"
        app:itemIconTint="@android:color/white"
        app:itemTextColor="@android:color/white"
        app:menu="@menu/activity_bottomnav_drawer" />

</android.support.design.widget.CoordinatorLayout>

content_mail.xml

*1024*
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.masterdetailexample.MainActivity"
    tools:showIn="@layout/app_bar_nav">


    <android.support.constraint.Guideline
        android:id="@+id/guideline_90"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent=".80" />

    <FrameLayout
        android:id="@+id/detail_fragment_container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/bgDetail">
    </FrameLayout>

    <FrameLayout
        android:id="@+id/total_fragment_container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_gravity="end"
        android:background="@color/bgBottomTotal"
        app:layout_constraintBottom_toTopOf="@id/guideline_90">
    </FrameLayout>

</android.support.constraint.ConstraintLayout>

colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="red">#FF0000</color>
    <color name="black">#000000</color>
    <color name="grey">#BBBBBB</color>
    <color name="white">#FFFFFF</color>
    <color name="blue">#03A9F4</color>

    <color name="colorPrimary">#7b4bff</color>
    <color name="colorPrimaryDark">#6539ba</color>
    <color name="colorAccent">#FF4081</color>
    <color name="bgBottomNavigation">#fe485a</color>
    <color name="bgBottomTotal">#fe885a</color>
    <color name="bgDetail">#999999</color>
    <color name="colorMain">#7b4bff</color>
    <color name="windowBackground">#fdfdfd</color>
</resources>

при поворотеустройство il ландшафтный режим, у меня та же проблема выше плюс еще одна проблема с BottomNavigationView , я хотел бы удалить пустое пространство слева и справа (или заменить на тот же цвет BottomNavigationView)

1 Ответ

0 голосов
/ 30 декабря 2018

Найдено решение: я пытаюсь реализовать свой макет, но не могу получить правильный макет.Когда мое устройство находится в портретном режиме, и я использую ограничение. Гид, я пытаюсь найти правильный номер, чтобы поместить нижнюю часть ORANGE FrameLayout рядом с BottomNavigationView.Если я использую app: layout_constraintGuide_percent = ". 90" рядом с "правильным" числом, но я думаю, что это неправильно ... также, когда я переводю устройство в альбомный режим, ORANGE FrameLayout исчезает и длявновь появиться я должен установить app: layout_constraintGuide_percent = ". 80" .Я новичок

portrait

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: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"
    android:background="@color/colorMain"
    tools:openDrawer="start">


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

    <!-- The activity_nav_drawer drawer that comes from the left -->
    <!-- Note that `android:layout_gravity` needs to be set to 'start' -->
    <android.support.design.widget.NavigationView
        android:id="@+id/master_fragment_container"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        android:fitsSystemWindows="true"/>
        <!--app:headerLayout="@layout/nav_header_nav"-->
        <!--app:menu="@menu/activity_nav_drawer" />-->

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

!!!РЕДАКТИРОВАТЬ, чтобы решить проблему

app_bar_nav.xml

    <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.masterdetailexample.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:theme="@style/AppTheme">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme" />

    </android.support.design.widget.AppBarLayout>

    <!--<include layout="@layout/content_main" />-->


    <android.support.constraint.ConstraintLayout
        android:id="@+id/constrain_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <FrameLayout
            android:id="@+id/detail_fragment_container"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:background="@color/bgDetail"
            app:layout_constraintTop_toTopOf="@id/constrain_container"
            app:layout_constraintBottom_toTopOf="@id/total_fragment_container">

        </FrameLayout>

        <FrameLayout
            android:id="@+id/total_fragment_container"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_gravity="end"
            android:background="@color/bgBottomTotal"
            app:layout_constraintBottom_toTopOf="@id/bottom_navigation">

        </FrameLayout>
        <android.support.design.widget.BottomNavigationView
            android:id="@+id/bottom_navigation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="@color/bgBottomNavigation"
            android:foreground="?attr/selectableItemBackground"
            app:itemBackground="@color/bgBottomNavigation"
            app:itemIconTint="@android:color/white"
            app:itemTextColor="@android:color/white"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:menu="@menu/activity_bottomnav_drawer" />
    </android.support.constraint.ConstraintLayout>

</android.support.design.widget.CoordinatorLayout>

!! РЕДАКТИРОВАТЬ не используется !! content_mail.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.masterdetailexample.MainActivity"
    tools:showIn="@layout/app_bar_nav">


    <android.support.constraint.Guideline
        android:id="@+id/guideline_90"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent=".80" />

    <FrameLayout
        android:id="@+id/detail_fragment_container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/bgDetail">
    </FrameLayout>

    <FrameLayout
        android:id="@+id/total_fragment_container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_gravity="end"
        android:background="@color/bgBottomTotal"
        app:layout_constraintBottom_toTopOf="@id/guideline_90">
    </FrameLayout>

</android.support.constraint.ConstraintLayout>

colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="red">#FF0000</color>
    <color name="black">#000000</color>
    <color name="grey">#BBBBBB</color>
    <color name="white">#FFFFFF</color>
    <color name="blue">#03A9F4</color>

    <color name="colorPrimary">#7b4bff</color>
    <color name="colorPrimaryDark">#6539ba</color>
    <color name="colorAccent">#FF4081</color>
    <color name="bgBottomNavigation">#fe485a</color>
    <color name="bgBottomTotal">#fe885a</color>
    <color name="bgDetail">#999999</color>
    <color name="colorMain">#7b4bff</color>
    <color name="windowBackground">#fdfdfd</color>
</resources>

, когда я поворачиваю устройство il Пейзажный режим, у меня та же проблема выше плюс другая проблемас BottomNavigationView , я хотел бы удалить пустое пространство слева и справа (или заменить на тот же цвет BottomNavigationView)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...