Как я могу положить рамку в нижней части приложения? - PullRequest
2 голосов
/ 13 января 2011

Я хочу поместить рамку внизу, выполнив это:

 <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 голосов
/ 09 ноября 2012

Не уверен, что это полностью правильно, но я работаю над аналогичным приложением с кучей макетов кадров, которые генерируются динамически и должны были переключиться на относительные макеты, чтобы использовать 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 голосов
/ 27 сентября 2017

Это метод полной программируемости:

 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 {

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

}

0 голосов
/ 13 января 2011

Внизу что? Каков ваш родительский макет? Если вы используете RelativeLayout, удалите атрибут layout_gravity и вместо этого добавьте атрибут alignParentBottom = "true".

...