Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.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,为了这件事我一整天都在胡思乱想 我试图在屏幕底部有两个线性布局,每个都有几个底部。我想要一个线性布局在右边,一个在左边 到目前为止我有 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="f

为了这件事我一整天都在胡思乱想

我试图在屏幕底部有两个线性布局,每个都有几个底部。我想要一个线性布局在右边,一个在左边

到目前为止我有

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<LinearLayout
    android:id="@+id/home_layout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
    <!-- MAIN CONTENT WILL GO HERE -->
</LinearLayout>

<LinearLayout
    android:id="@+id/ad_layout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/home_layout"
    android:layout_alignParentBottom="true"
    android:gravity="bottom" >

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="right"
        android:background="@android:color/white"
        android:gravity="right"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="£12.50" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Rate1 **** " />
    </LinearLayout>
</LinearLayout>

</RelativeLayout>

产生

现在我尝试在左侧添加第二个布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<LinearLayout
    android:id="@+id/home_layout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
    <!-- MAIN CONTENT WILL GO HERE -->
</LinearLayout>

<LinearLayout
    android:id="@+id/ad_layout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/home_layout"
    android:layout_alignParentBottom="true"
    android:gravity="bottom" >

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="left"
        android:background="@android:color/white"
        android:gravity="left"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="£12.50" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Rate1 **** " />
    </LinearLayout>

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="right"
        android:background="@android:color/white"
        android:gravity="right"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="£12.50" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Rate1 **** " />
    </LinearLayout>
</LinearLayout>

</RelativeLayout>

产生:


有什么想法吗?

您可以制作如下内容:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/home_layout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:layout_weight="1" >
        <!-- MAIN CONTENT WILL GO HERE -->
    </LinearLayout>

    <FrameLayout
        android:id="@+id/ad_layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0" >

       <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:background="@android:color/white"
            android:gravity="left"
            android:orientation="vertical" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="£12.50" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Rate1 **** " />
        </LinearLayout>

        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:background="@android:color/white"
            android:gravity="right"
            android:orientation="vertical" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="£13.50" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Rate2 **** " />
        </LinearLayout>
    </FrameLayout>

</LinearLayout>

您可以制作如下内容:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/home_layout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:layout_weight="1" >
        <!-- MAIN CONTENT WILL GO HERE -->
    </LinearLayout>

    <FrameLayout
        android:id="@+id/ad_layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0" >

       <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:background="@android:color/white"
            android:gravity="left"
            android:orientation="vertical" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="£12.50" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Rate1 **** " />
        </LinearLayout>

        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:background="@android:color/white"
            android:gravity="right"
            android:orientation="vertical" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="£13.50" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Rate2 **** " />
        </LinearLayout>
    </FrameLayout>

</LinearLayout>


您应该为布局使用android:layout\u weight属性,这样您可以指定每个LinearLayout视图组占用的屏幕面积,或者如上面的注释所述,您需要更改布局,以便它们都不会试图填充父视图组。您可以将其设置为wrap_content,这可能看起来不太好看,因为屏幕上可能有未被任何视图组填充的空白

您应该为布局使用android:layout_weight属性,以便您可以指定每个LinearLayout视图组占用多少屏幕,或者如上面的注释所示,您需要更改布局,以便它们都不会试图填充父视图组。您可以将其设置为“包裹内容”,这可能看起来不太好看,因为屏幕上可能有任何视图组都无法填充的空白

您的两个子线性布局都有

android:layout_width="fill_parent" 
android:layout_height="fill_parent"

这行不通。如果要均匀分割空间,请使用
布局\权重

查看您的两个子线性布局

android:layout_width="fill_parent" 
android:layout_height="fill_parent"

这行不通。如果您想均匀地分割空间,请使用
layout\u weight

查看您的两个子线性布局都有
android:layout\u width=“fill\u parent”android:layout\u height=“fill\u parent”
,这将不起作用。如果你想均匀地分割空间,可以考虑使用layou\u weight。这很有效!我使用了android:layout\u weight=“1”你能回答这个问题吗?这样我就可以将你的答案标记为正确吗?你的两个子线性布局都有
android:layout\u width=“fill\u parent”android:layout\u height=“fill\u parent”
,这不起作用。如果你想均匀地分割空间,可以考虑使用layou\u weight。这很有效!我使用了android:layout_weight=“1”你能回答这个问题吗?这样我就可以把你的答案标记为正确的?