我正在尝试实现布局,但是我无法获得正确的布局。 当我的设备处于“纵向”模式并且使用constraint.Guideline时,我尝试找到正确的数字以将ORANGE FrameLayout底部放置在BottomNavigationView附近。 如果我使用 app:layout_constraintGuide_percent =“。90” 靠近“正确”的数字,但我认为这是不正确的方法...也将设备置于横向模式时,ORANGE FrameLayout会消失要重新出现,我必须设置 app:layout_constraintGuide_percent =“。80” 。我是新手
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
<?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>
当我在横向模式下旋转设备时,我遇到上面的相同问题以及 BottomNavigationView 的另一个问题,我想删除左右两边的空白(或替换为与BottomNavigationView的颜色相同)
答案 0 :(得分:0)
找到了解决方案: 我正在尝试实现布局,但无法获得正确的布局。 当我的设备处于“纵向”模式并且使用constraint.Guideline时,我尝试找到正确的数字以将ORANGE FrameLayout底部放置在BottomNavigationView附近。 如果我使用 app:layout_constraintGuide_percent =“。90” 靠近“正确”的数字,但我认为这是不正确的方法...也将设备置于横向模式时,ORANGE FrameLayout会消失要重新出现,我必须设置 app:layout_constraintGuide_percent =“。80” 。我是新手
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>
当我在横向模式下旋转设备时,我遇到上面的相同问题以及 BottomNavigationView 的另一个问题,我想删除左右两边的空白(或替换为与BottomNavigationView的颜色相同)