Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使应用程序占屏幕大小的百分比_Android_Android Layout - Fatal编程技术网

Android 如何使应用程序占屏幕大小的百分比

Android 如何使应用程序占屏幕大小的百分比,android,android-layout,Android,Android Layout,我正在尝试使用percentRelativeLayout使我的应用程序的屏幕宽度达到90%,屏幕高度达到50% 我的布局由两个片段组成:1)左侧是4个按钮,2)右侧是一个容器,每次单击按钮都会插入不同的片段 当我使用percentRelativeLayout或percentFrameLayout使屏幕的高度为50%,宽度为90%时,我得到了下面的结果,在一个框中,我得到了50%的高度和90%的宽度,这个框是整个屏幕高度的50%,整个屏幕宽度的90%。有人知道我怎么解决这个问题吗 我已经试着将我的

我正在尝试使用percentRelativeLayout使我的应用程序的屏幕宽度达到90%,屏幕高度达到50%

我的布局由两个片段组成:1)左侧是4个按钮,2)右侧是一个容器,每次单击按钮都会插入不同的片段

当我使用percentRelativeLayout或percentFrameLayout使屏幕的高度为50%,宽度为90%时,我得到了下面的结果,在一个框中,我得到了50%的高度和90%的宽度,这个框是整个屏幕高度的50%,整个屏幕宽度的90%。有人知道我怎么解决这个问题吗

我已经试着将我的布局高度和宽度设置为与我的两个布局的父级匹配,结果要么相同,要么应用程序占据整个屏幕。我还确保使用占据整个屏幕的主题,而不是对话框主题。我还尝试使用一个父RelativeLayout,其中嵌套了percentRelativeLayout,并将layout_widthPercent和layout_heightPercent应用于我的片段,得到了相同的结果

<android.support.percent.PercentFrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_gravity="center"
    android:background="@drawable/rounded_edges"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    app:layout_widthPercent="90%"
    app:layout_heightPercent="50%"
    >
<fragment
    android:id="@+id/menuFragment"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_margin="5dp"
    class="it.anddev.bradipao.janus.MenuFragment"
    tools:layout="@layout/fr_menu">
</fragment>

<FrameLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</LinearLayout>

</android.support.percent.PercentFrameLayout>


看起来,菜单片段的宽度约占其对话框样式父项总宽度的30%,内容约占70%。我会在
PercentFrameLayout
中使用
PercentRelativeLayout
,如下所示

<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentFrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.percent.PercentRelativeLayout 
        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:layout_gravity="center"
        android:background="@drawable/rounded_edges"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar"
        app:layout_heightPercent="50%"
        app:layout_widthPercent="90%">

        <fragment
            android:id="@+id/menuFragment"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:layout_alignParentStart="true"
            app:layout_widthPercent="30%"
            class="it.anddev.bradipao.janus.MenuFragment"
            tools:layout="@layout/fr_menu">
        </fragment>


        <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_toEndOf="@+id/menuFragment" />

    </android.support.percent.PercentRelativeLayout>

</android.support.percent.PercentFrameLayout>


至于出现在你的欢迎片段后面的双白色背景,如果不看它的布局文件,我真的无法说出为什么会发生这种情况。您可能需要删除布局中您在
容器中替换的所有片段的背景
FrameLayout

看起来菜单片段的宽度占其对话框样式父级总宽度的30%左右,而内容占70%左右。我会在
PercentFrameLayout
中使用
PercentRelativeLayout
,如下所示

<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentFrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.percent.PercentRelativeLayout 
        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:layout_gravity="center"
        android:background="@drawable/rounded_edges"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar"
        app:layout_heightPercent="50%"
        app:layout_widthPercent="90%">

        <fragment
            android:id="@+id/menuFragment"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:layout_alignParentStart="true"
            app:layout_widthPercent="30%"
            class="it.anddev.bradipao.janus.MenuFragment"
            tools:layout="@layout/fr_menu">
        </fragment>


        <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_toEndOf="@+id/menuFragment" />

    </android.support.percent.PercentRelativeLayout>

</android.support.percent.PercentFrameLayout>


至于出现在你的欢迎片段后面的双白色背景,如果不看它的布局文件,我真的无法说出为什么会发生这种情况。您可能需要删除布局中的背景,以便在
容器中替换所有片段
框架布局

我更改为显示的内容
按钮
被删除带有四个
按钮的
菜单片段
,以模拟您想要的图像,您可以将这四个
按钮
替换为
菜单片段

<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:background="@android:color/holo_blue_dark"
        android:padding="4dp"
        app:layout_heightPercent="50%"
        app:layout_marginPercent="5%"
        app:layout_widthPercent="90%">

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_gravity="center_vertical"
            android:layout_margin="4dp"
            android:layout_weight="0.3"
            android:background="@android:color/holo_purple"
            android:contentDescription="this is where you can keep your buttons"
            android:gravity="center"
            android:orientation="vertical">


            <Button
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_margin="4dp"
                android:layout_weight="1"
                android:text="First"
                android:textAllCaps="false" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_margin="4dp"
                android:layout_weight="1"
                android:text="Second"
                android:textAllCaps="false" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_margin="4dp"
                android:layout_weight="1"
                android:text="Third"
                android:textAllCaps="false" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_margin="4dp"
                android:layout_weight="1"
                android:text="Forth"
                android:textAllCaps="false" />
        </LinearLayout>

        <FrameLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_gravity="bottom"
            android:layout_margin="4dp"
            android:layout_weight="0.7"
            android:background="@android:color/holo_green_dark"
            android:contentDescription="this would be your frame container"></FrameLayout>
    </LinearLayout>

</android.support.percent.PercentFrameLayout>


我更改为显示的
按钮
被删除
菜单片段
带有四个
按钮
为了模拟您想要的图像,您可以将这四个
按钮
替换为
菜单片段

<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:background="@android:color/holo_blue_dark"
        android:padding="4dp"
        app:layout_heightPercent="50%"
        app:layout_marginPercent="5%"
        app:layout_widthPercent="90%">

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_gravity="center_vertical"
            android:layout_margin="4dp"
            android:layout_weight="0.3"
            android:background="@android:color/holo_purple"
            android:contentDescription="this is where you can keep your buttons"
            android:gravity="center"
            android:orientation="vertical">


            <Button
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_margin="4dp"
                android:layout_weight="1"
                android:text="First"
                android:textAllCaps="false" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_margin="4dp"
                android:layout_weight="1"
                android:text="Second"
                android:textAllCaps="false" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_margin="4dp"
                android:layout_weight="1"
                android:text="Third"
                android:textAllCaps="false" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_margin="4dp"
                android:layout_weight="1"
                android:text="Forth"
                android:textAllCaps="false" />
        </LinearLayout>

        <FrameLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_gravity="bottom"
            android:layout_margin="4dp"
            android:layout_weight="0.7"
            android:background="@android:color/holo_green_dark"
            android:contentDescription="this would be your frame container"></FrameLayout>
    </LinearLayout>

</android.support.percent.PercentFrameLayout>


你能解释一下你想要实现什么吗?此外,请将代码张贴在此处而不是图像文件中。您可以使用对话框主题进行活动。请勾选此项抱歉,但它仍然没有说明您正在努力实现什么?您能否分享布局外观的大致图像like@MuchOverflow我已经更新了我的帖子,以显示我想要什么,并发布了我正在使用的代码,如果你有任何建议。谢谢@PankajNimgade我已经更新了我的帖子,以显示我想要什么,并发布了我正在使用的代码,如果您有任何建议的话。谢谢你能解释一下你想要实现什么吗?此外,请将代码张贴在此处而不是图像文件中。您可以使用对话框主题进行活动。请勾选此项抱歉,但它仍然没有说明您正在努力实现什么?您能否分享布局外观的大致图像like@MuchOverflow我已经更新了我的帖子,以显示我想要什么,并发布了我正在使用的代码,如果你有任何建议。谢谢@PankajNimgade我已经更新了我的帖子,以显示我想要什么,并发布了我正在使用的代码,如果您有任何建议的话。谢谢