简体   繁体   中英

how can i put the framelayout in the bottom of the application?

i want to put a framelayout in the bottom by doing this :

 <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>

But it doesn't work . It's staying in the middle of my application.

This is the whole thing :

<?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>

Not sure this is totally correct but I'm working on an similar app with a bunch of frame layouts that get dynamically generated and had to switch to relative layouts to use the android:layout_below="@id/some_id" to 'stack' my layouts. I'm using fragments and it seems to be working well.

Example layout:

<?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>

This is full programmability method :

 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)  ));



            }
        });

Here's ekran class :

public class 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;
}

}

In the bottom of what? What is your parent layout? If you're using a RelativeLayout, remove the layout_gravity attribute, and add the alignParentBottom="true" attribute instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM