【问题标题】:Android Second Layout cannot fill the screenAndroid Second Layout 无法填满屏幕
【发布时间】:2014-03-18 17:56:36
【问题描述】:

我想让我的第二个布局填满整个屏幕并覆盖所有第一个布局,但它只是像大弹出窗口一样一直显示,有什么解决方案吗?

这是我当前显示的布局的描述:

|====================|
|first layout        |
|  |==============|  |
|  |              |  |
|  |second layout |  |
|  |              |  |
|  |              |  |
|  |              |  |
|  |              |  |
|  |              |  |
|  |              |  |
|  |              |  |
|  |              |  |
|  |==============|  |
|                    |
|====================|

我需要的是这样的:

|====================|
|second layout       |
|                    |
|                    |
|                    |
|                    |
|                    |
|                    |
|                    |
|                    |
|                    |
|                    |
|                    |
|                    |
|                    |
|====================|

这是我的第一个布局 xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <FrameLayout
        android:id="@+id/frameLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginBottom="60dp" >

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

            <Button
                android:id="@+id/btnRenungan"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:text="Renungan" />

            <Button
                android:id="@+id/btnGambar"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="0dp"
                android:text="Gambar" />

            <Button
                android:id="@+id/btnLokasi"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Lokasi" />
        </LinearLayout>

        <LinearLayout android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true" android:layout_marginBottom="58px"
            android:layout_height="45px" android:layout_width="200px"
            android:id="@+id/lin_progress_bar" android:visibility="invisible">
            <ProgressBar
               android:id="@+id/progressBar"
               style="?android:attr/progressBarStyleLarge"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_alignLeft="@+id/frameLayout1"
               android:layout_alignParentBottom="true" />
            <TextView android:id="@+id/TextView01" android:layout_height="fill_parent"
                android:layout_width="fill_parent" android:gravity="center_vertical"
                android:textStyle="bold" android:text="Loading..."
                android:layout_marginLeft="10px" android:textSize="23px"
                android:textColor="#808080"></TextView>
        </LinearLayout>
    </FrameLayout>
</RelativeLayout>

这是我的第二个布局 xml:

<?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:background="@drawable/background"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/listRenungan"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="false" 
        android:layout_weight="2"/>

    <ImageButton
         android:id="@+id/btnBack"
         android:layout_width="50dp"
         android:layout_height="50dp"
         android:layout_gravity="center"
         android:background="@drawable/button_back"
         android:drawable="@drawable/button_back"
         android:scaleType="fitXY" />

</LinearLayout>

这是我调用第二个布局的代码:

    case R.id.btnRenungan:
        //Activity Renungan
        Intent intentSelectionRenungan=new Intent(this, selectionRenungan.class);
        startActivity(intentSelectionRenungan);

【问题讨论】:

  • 你想像对话框一样显示第二个布局
  • 嗨!小澄清:您说的是两种不同的活动,对吧?
  • 如果你在谈论活动,你的清单中可能会有这行:android:theme="@android:style/Theme.Dialog"。如果有,请删除它。
  • 是的,有两种不同的活动
  • 是的,麦克工作得很好。谢谢

标签: android android-layout


【解决方案1】:

删除

android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"

来自RelativeLayout,它应该可以工作。

【讨论】:

    【解决方案2】:

    你应该使用weight

    在此它将创建 3 行页脚 geader 和中间部分,您可以调整它将计入 %

    【讨论】:

      【解决方案3】:

      如果你想让它变得更好,你可以将 Fragment 与这个一起使用,你可以在一个布局中制作多个布局。

      看看这张照片,你可以在一侧拥有例如 Listview,而在另一侧拥有例如 ImageView

      http://i.stack.imgur.com/BW4Ug.png

      【讨论】:

        【解决方案4】:

        将您的第二个布局更改为:

        <LinearLayout android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true" 
                android:layout_height="match_parent" android:layout_width="match_parent"
                android:id="@+id/lin_progress_bar" android:visibility="invisible">
                <ProgressBar
                   android:id="@+id/progressBar"
                   style="?android:attr/progressBarStyleLarge"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:layout_alignLeft="@+id/frameLayout1"
                   android:layout_alignParentBottom="true" />
                <TextView android:id="@+id/TextView01" android:layout_height="fill_parent"
                    android:layout_width="fill_parent" android:gravity="center_vertical"
                    android:textStyle="bold" android:text="Loading..."
                    android:layout_marginLeft="10px" android:textSize="23px"
                    android:textColor="#808080"></TextView>
            </LinearLayout>
        

        【讨论】:

          【解决方案5】:

          删除@Boris 所说的填充,除此之外,将您的框架布局高度和宽度设置为 match_parent。

          <FrameLayout
              android:id="@+id/frameLayout1"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_alignParentBottom="true"
              android:layout_alignParentLeft="true"
              android:layout_alignParentRight="true"
              android:layout_alignParentTop="true"
              android:layout_marginBottom="60dp" >
          

          【讨论】:

          • 您的第二个布局是指您的 FrameLayout 对吗?另外,你能解释一下你到底想在这里做什么吗?
          猜你喜欢
          • 2018-01-07
          • 2012-02-16
          • 2017-10-26
          • 1970-01-01
          • 1970-01-01
          • 2014-03-15
          • 2011-01-24
          • 2013-08-18
          • 1970-01-01
          相关资源
          最近更新 更多