如何将framelayout放在应用程序的底部?

时间:2011-01-13 15:10:28

标签: android frame

我想通过这样做将framelayout放在底部:

 <FrameLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="@color/darkblue"
    >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Bottom"
        android:textSize="30px"
        android:textColor="@color/white"
        android:layout_gravity="center"
       />
  </FrameLayout>

但它不起作用。它停留在我的应用程序中间。

这就是全部:

<?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:background="@color/white"
    >
    <FrameLayout
        android:id="@+id/first"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/darkblue"
        >
        <ImageView
            android:id="@+id/btn1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:src="@drawable/back4"
            />
        <TextView  
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:text="Title"
            android:textSize="30px"
            android:textColor="@color/white"
            android:layout_gravity="center"
            />
    </FrameLayout>

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:id="@+id/second"
        android:layout_below="@id/first"
        >
        <ImageView
            android:id="@+id/banner"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/chuck"
            />
    </FrameLayout>

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:id="@+id/third"
        android:layout_below="@id/second"
        >
        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            >
            <TextView
                android:id="@+id/sum"
                android:text="Summary "
                android:textSize="25px"
                android:textColor="@color/black"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                />
            <ImageView
                android:id="@+id/s_btn"
                android:src="@drawable/next"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/sum"
                android:layout_alignTop="@id/sum"
                />
            <TextView
                android:id="@+id/blank"
                android:text=" "
                android:textSize="25px"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/sum"
                />
            <TextView
                android:id="@+id/airdate"
                android:text="Air Date : "
                android:textSize="25px"
                android:textColor="@color/black"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/blank"
                />
            <TextView
                android:id="@+id/blank2"
                android:text=" "
                android:textSize="25px"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/airdate"
                />
            <TextView
                android:id="@+id/airtime"
                android:text="Air Time : "
                android:textSize="25px"
                android:textColor="@color/black"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/blank2"
                />
        </RelativeLayout>
    </FrameLayout>

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/darkblue"
        android:id="@+id/fourth"
        android:layout_below="@id/third"
        android:layout_alignParentBottom="true"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Bottom"
            android:textSize="30px"
            android:textColor="@color/white"
            android:layout_gravity="center"
            />
    </FrameLayout>

</RelativeLayout>

3 个答案:

答案 0 :(得分:0)

在底部是什么?你的父布局是什么?如果您正在使用RelativeLayout,请删除layout_gravity属性,然后添加alignParentBottom =“true”属性。

答案 1 :(得分:0)

不确定这是完全正确的但我正在开发一个类似的应用程序,其中包含一系列动态生成的框架布局,并且必须切换到相对布局以使用android:layout_below="@id/some_id"来“堆叠”我的布局。我正在使用片段,它似乎运作良好。

示例布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/top_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:background="@drawable/bg">

    <!-- Content Foo -->

</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/middle_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_below="@id/top_layout"
    android:background="@drawable/bg">

    <!-- Content Foo -->

</RelativeLayout>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/bottom_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:layout_below="@id/middle_layout"
    android:background="@drawable/bg">

    <!-- Content Foo -->

</RelativeLayout>

答案 2 :(得分:0)

这是完整的可编程方法:

 EKRAN MY_EKRAN;
 context = getApplicationContext();
 MY_EKRAN = new EKRAN( contex );


 YOUR_FRAMELAYOUT =  findViewById(R.id.PUT_ID_FOR_YOUR_FRAMELAYOUT);

  YOUR_FRAMELAYOUT.post(new Runnable() {

            @Override
            public void run() {

                YOUR_FRAMELAYOUT.getLayoutParams().width = MY_EKRAN.W(105);
                YOUR_FRAMELAYOUT.getLayoutParams().height = MY_EKRAN.H(10);

             //   banner.getLayoutParams().width = ( MY_EKRAN.H(10));
             //   banner.getLayoutParams().width = ( MY_EKRAN.H(10));         

                YOUR_FRAMELAYOUT.setY( MY_EKRAN.H(90) );

             // also like this 
             // YOUR_FRAMELAYOUT.setLayoutParams(new LinearLayout.LayoutParams( MY_EKRAN.W(100)  ,MY_EKRAN.H(30)  ));



            }
        });

这是ekran课程:

公共课EKRAN {

DisplayMetrics dm = new DisplayMetrics();
Point size_ = new Point();
static int width;
static int height;

EKRAN(Context CONTEXT_) {

    dm = CONTEXT_.getResources().getDisplayMetrics();
    int densityDpi = dm.densityDpi;
    height = dm.heightPixels;
    width = dm.widthPixels;

}

public static int WIDTH() {

    return width;

}
public static int HEIGHT(){

    return height;

}
public int W( int PER_ ){

    return width/100*PER_;

}
public int H( int PER_   ){


    return height/100*PER_;

}

//////////////////
//extras
/////////////////
public int GET_PIX_FROM_DP ( float DP_VALUE )
{
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DP_VALUE , dm );
}

public int GET_PIX_FROM_DP2 ( float DP_VALUE )
{
    float res = DP_VALUE * ( dm.ydpi / 160f);
    return  (int) res;
}

}