2011-01-13 26 views
2

我想這樣做是爲了把在的FrameLayout底部:我該如何將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> 

回答

0

在什麼樣的底部?你的父母佈局是什麼?如果您使用的是RelativeLayout,請刪除layout_gravity屬性,然後添加alignParentBottom =「true」屬性。

+0

在我的應用程序的底部,種脈衝應用程序 – Tsunaze 2011-01-13 15:46:51

+0

您的FrameLayout是在父佈局內​​。它是什麼?同樣,如果它是一個RelativeLayout,則該評論適用。 – kcoppock 2011-01-13 15:52:50

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



      } 
     }); 

這裏的熒光屏類:

公共類熒光屏{

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

}

相關問題