FrameLayout × RelativeLayout × LinearLayout

レイアウト

概要

 状態:-  閲覧数:1,140  投稿日:2014-07-19  更新日:2014-07-21  

レイアウト例

 閲覧数:358 投稿日:2014-07-19 更新日:2014-07-25 



構成


・1つのFrameLayoutの中に、LinearLayout、Button、RelativeLayout を配置

FrameLayout
 ┃ 
 ┗RelativeLayout
   ├ImageView
   │├android:id="@+id/ImageView1"
   │
   └LinearLayout
       │├android:layout_alignBottom="@+id/ImageView1" … ImageViewの下端を基準
       │├android:layout_alignParentRight="true" … trueの場合、このビューの左端は、親の右端に一致
       │├android:layout_alignTop="@+id/ImageView1" … ImageViewの上端を基準
       │├android:layout_toRightOf="@+id/ImageView1" … ImageViewの右に配置
       │
       ├TextView
       └TextView


コード


▼/MainActivity.java
public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.assignment_2_1);
}


▼/res/layout/assignment_2_1.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   tools:context=".MainActivity" >

   <!-- このLinearLayoutをRelativeLayoutに変更して同じレイアウトを実現してください -->
   <!-- 変更後 -->

   <RelativeLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:background="#ffc356"
       android:padding="4dp" >

       <ImageView
           android:id="@+id/ImageView1"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_marginRight="4dp"
           android:background="#ffffff"
           android:src="@drawable/ic_launcher" />

       <LinearLayout
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignBottom="@+id/ImageView1"
           android:layout_alignParentRight="true"
           android:layout_alignTop="@+id/ImageView1"
           android:layout_toRightOf="@+id/ImageView1"
           android:orientation="vertical" >

           <TextView
               android:layout_width="match_parent"
               android:layout_height="0dp"
               android:layout_weight="1"
               android:background="#ff9630" />

           <TextView
               android:layout_width="match_parent"
               android:layout_height="0dp"
               android:layout_weight="1"
               android:background="#ffedc6" />
       </LinearLayout>
   </RelativeLayout>

</FrameLayout>


一番外側のFrameLayoutはなくても良い?
▼/res/layout/assignment_2_1_1.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:background="#ffc356"
   android:padding="4dp"
   tools:context=".MainActivity" >

       <ImageView
           android:id="@+id/ImageView1"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_marginRight="4dp"
           android:background="#ffffff"
           android:src="@drawable/ic_launcher" />

       <LinearLayout
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignBottom="@+id/ImageView1"
           android:layout_alignParentRight="true"
           android:layout_alignTop="@+id/ImageView1"
           android:layout_toRightOf="@+id/ImageView1"
           android:orientation="vertical" >

           <TextView
               android:layout_width="match_parent"
               android:layout_height="0dp"
               android:layout_weight="1"
               android:background="#ff9630" />

           <TextView
               android:layout_width="match_parent"
               android:layout_height="0dp"
               android:layout_weight="1"
               android:background="#ffedc6" />
       </LinearLayout>
</RelativeLayout>



LinearLayout × FrameLayout

LinearLayout × RelativeLayout

コメント投稿(ログインが必要)