Breaking News
recent

Membuat Layout Sederhana dengan Android Studio

Modul 2
Mobile Programming

Membuat layout seperti gambar yang sudah ditentukan sebelumnya.
Source code pada activy_main.xml :

<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
   
tools:context="com.example.erull_umem.relative_layout.MainActivity">
    <
LinearLayout
       
android:layout_width="2000dp"
       
android:layout_height="wrap_content"
       
android:background="#A0DD0A"
       
android:layout_margin="10dp"
       
android:id="@+id/utama">
        <
TextView
           
android:layout_width="wrap_content"
           
android:layout_height="wrap_content"
           
android:textAppearance="?android:attr/textAppearanceLarge"
           
android:text="TITLE" />
    </
LinearLayout>
    <
LinearLayout
       
android:layout_width="match_parent"
       
android:layout_height="match_parent"
       
android:orientation="vertical"
       
android:layout_below="@+id/utama">
        <
LinearLayout
           
android:layout_width="match_parent"
           
android:layout_height="match_parent"
           
android:layout_weight="1"
           
android:background="#FFFA00"
           
android:layout_below="@+id/utama">
            <
TextView
                
android:layout_height="100dp"
               
android:layout_width="0dp"
               
android:layout_weight="1"
               
android:textAppearance="?android:attr/textAppearanceLarge"
               
android:text="Text1"
               
android:layout_margin="10dp"
               
android:textColor="#000000"
               
android:background="#FF0000"
               
/>
            <
TextView
               
android:layout_height="100dp"
               
android:layout_width="0dp"
               
android:layout_weight="1"
               
android:textAppearance="?android:attr/textAppearanceLarge"
               
android:text="Text2"
               
android:layout_margin="10dp"
               
android:textColor="#000000"
               
android:background="#00FF00"
               
android:onClick="@android:string/paste" />
            <
TextView
               
android:layout_height="100dp"
               
android:layout_width="0dp"
               
android:layout_weight="1"
               
android:textAppearance="?android:attr/textAppearanceLarge"
               
android:text="Text3"
               
android:layout_margin="10dp"
               
android:textColor="#000000"
               
android:background="#0000FF"/>
        </
LinearLayout>
        <
LinearLayout
           
android:layout_width="match_parent"
           
android:layout_height="match_parent"
           
android:layout_weight="1"
           
android:background="#FFFF88"
           
android:layout_below="@+id/utama">
            <
TextView
               
android:layout_height="100dp"
               
android:layout_width="wrap_content"
               
android:text="Text4"
               
android:layout_margin="10dp"
               
android:textColor="#000000"
               
android:background="#FF00FF"/>
            <
TextView
               
android:layout_height="100dp"
               
android:layout_width="wrap_content"

               
android:text="Text5"
               
android:layout_margin="10dp"
               
android:textColor="#000000"
               
android:background="#00FFFF"/>
            <
LinearLayout
               
android:layout_width="match_parent"
               
android:layout_height="100dp"
               
android:background="#555555"
               
android:orientation="vertical"
               
android:layout_margin="10dp">
                <
TextView
                   
android:layout_height="wrap_content"
                   
android:layout_width="match_parent"
                   
android:layout_margin="10dp"

                    
android:text="Text6"
                   
android:textAppearance="?android:attr/textAppearanceLarge"
                   
android:textColor="#000000"
                   
android:background="#FF00FF"
                   
/>
                <
TextView
                   
android:layout_height="wrap_content"
                   
android:layout_width="match_parent"
                   
android:layout_margin="10dp"


                   
android:text="Text7"
                   
android:textAppearance="?android:attr/textAppearanceLarge"
                   
android:textColor="#000000"
                   
android:background="#00FFFF"

                  
/>
            </
LinearLayout>
        </
LinearLayout>
    </
LinearLayout>
</
RelativeLayout>


MainActivity.java :

package com.example.barni.modul2;

        import android.support.v7.app.AppCompatActivity;
        import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

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

Hasil Screenshot


Ahmad

Ahmad

No comments:

Post a Comment

Powered by Blogger.