ファイルmylayout.xmlに次のレイアウトがあります。私は透明なテーマを持っている私の活動のためにsetContentView(R.layout.mylayoutを)やっているとき、私のレイアウトは、画面の中央に表示なっている。このレイアウトで表示方法画面上からの相対的なレイアウト内容
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/yellow"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
android:id="@+id/Layout5"
android:layout_alignParentTop="true"
android:layout_gravity="top"
android:gravity="top"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/Layout6"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="top">
<ImageView
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="@color/green"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="5dp"
android:id="@+id/imageView"
android:layout_gravity="center_horizontal" />
<LinearLayout
android:id="@+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:layout_below="@+id/imageView">
<Button
android:id="@+id/btn1"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="@string/text_btn_1"
/>
<Button
android:id="@+id/btn2"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="@string/text_btn_2"
/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
。
私は動的にこのレイアウトの配置を変更したいので、中央(デフォルト)と(次のコードを使用して)下の表示が働いています。
LinearLayout lLayout = (LinearLayout) findViewById(R.id.Layout6);
RelativeLayout.LayoutParams relativeParas = (RelativeLayout.LayoutParams) lLayout.getLayoutParams();
relativeParas.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
lLayout.setLayoutParams(relativeParas);
しかし、何とか私はこのレイアウトを画面の上部に動的に表示する方法を理解できません。
ご協力いただければ幸いです。
はアンドロイド作る –
試しmatch_parentするlayout_height等しい "relativeParas.addRule(RelativeLayout.ALIGN_PARENT_TOPを);" – Nilabja
トップからのコンテンツを表示するアクティビティのマニフェストにテーマを定義するだけです。これは、タイトルバーを削除し、画面全体をカバーします。 android:theme = "@アンドロイド:style/Theme.Black.NoTitleBar"、layout_widthとHeight属性をxmlファイルのmatch_parentまたはfill_parentに設定します。 – Tara