小编Far*_*med的帖子

计算器应用程序在相同屏幕尺寸但不同 DPI 上的不同布局(420 DPI 与 480 DPI)

我做了这个非常简单的计算器布局。但我手机上的 480 DPI 和 420 DPI 不同。420DPI 屏幕右侧有可用空间,按钮比 480DPI 更薄。我使用 dp 作为按钮的度量单位和 sp 作为文本的度量单位。

我读了支持不同的屏幕尺寸 | Android 开发人员, 但无法真正解决我的问题。

我读过 dp 单位与屏幕的 DPI 无关,按钮将动态放大或缩小。那么为什么我的按钮在不同的 DPI 上变得更薄,即使我使用 dp 作为一个单位?

android android-layout

2
推荐指数
1
解决办法
1436
查看次数

状态栏下方的导航抽屉

如下图所示,导航抽屉中有四个项目。第一个隐藏在状态栏下。我想要它在工具栏的下方(汉堡图标的下方)。如果我尝试移动代码中的任何内容,那么我的折叠工具栏就会混乱,或者所有内容都固定在顶部。有什么帮助吗?这是我的XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    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"
    android:orientation="vertical">

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true">

            <android.support.design.widget.AppBarLayout
                android:id="@+id/app_bar_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                android:fitsSystemWindows="true">

                <android.support.design.widget.CollapsingToolbarLayout
                    android:id="@+id/collapsing_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed"
                    app:contentScrim="?attr/colorPrimary"
                    app:expandedTitleMarginStart="48dp"
                    app:expandedTitleMarginEnd="64dp"
                    android:fitsSystemWindows="true">

                    <ImageView
                        android:src="@drawable/nerdz_main_page"
                        android:id="@+id/image"
                        android:layout_width="match_parent"
                        android:layout_height="400dp"
                        android:scaleType="fitXY"
                        android:fitsSystemWindows="true"
                        app:layout_collapseMode="parallax"/>

                    <android.support.v7.widget.Toolbar
                        android:id="@+id/toolbar"
                        android:layout_width="match_parent"
                        android:layout_height="?attr/actionBarSize"
                        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                        app:layout_collapseMode="pin" />

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

            <android.support.v4.widget.NestedScrollView
                android:id="@+id/scroll"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clipToPadding="false"
                app:layout_behavior="@string/appbar_scrolling_view_behavior">

                <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <android.support.v7.widget.CardView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="24dp"
                        app:cardElevation="5dp"
                        android:text="this is a sample card "
                        app:cardUseCompatPadding="true">

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:orientation="vertical">

                            <TextView
                                android:id="@+id/title"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

android android-layout

2
推荐指数
1
解决办法
1318
查看次数

标签 统计

android ×2

android-layout ×2