【发布时间】:2018-12-31 01:04:14
【问题描述】:
我正在尝试实现我的布局,但我无法获得正确的布局。 当我的设备处于纵向模式并且我使用约束。指南时,我尝试找到正确的数字以将 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同色)
【问题讨论】:
-
请在your revision history 中找到您的解决方案并将其作为自己的答案发布。
-
对不起,但我不明白我必须做什么..我的回答
-
1.从修订历史记录 (source) 中获取您的解决方案,然后 2. 通过将其发布为答案来发布它:i.stack.imgur.com/4Hnjo.png