RELATİVE LAYOUT 1
Relative Layoutta şu şekilde olmaktadır.Alt alt dizilmez bir nesnenin konumunu diger nesneye göre belirlenmektedir.İki tür layout çeşidi vardır:Bunlar Relative Layout ,Linner Layouttur.Bu Layout çeşitlerinden Relative Layouttu kullanmaktayız.Relative Layout ör:
XML TARAFI
<?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="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<EditText
android:id="@+id/edt1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10sp"
android:hint="Enes Peçenek"/>
<EditText
android:id="@+id/edt2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/edt1"
android:layout_marginTop="10sp"
android:hint="Emre Peçenek"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/edt3"
android:layout_below="@id/edt2"
android:layout_marginTop="10sp"
android:hint="Enes Emre"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/edt4"
android:layout_below="@id/edt3"
android:layout_marginTop="10sp"
android:hint="EMREEE"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn1"
android:text="OKKKKKKKK"
android:layout_below="@+id/edt4"
android:textSize="30sp"
android:background="@color/colorPrimaryDark"
/>
</RelativeLayout> Burda Görüldügü gibi diger bir nesneyi diger nesneye göre belirledik.(layout_below) ile
belirttigimiz nesnenin altında olmasını sagladık.(android:layout_marginTop) ile de boyutunu belirttik. Oluşturdugumuz her nesneni ebatlarınında girişini belirledik.(Wrap_content)ile yazı buyuklugu kadar ayarladık. (fill_parent) ilede ekranın tamanını kapladık.EditTextde yazı yazmak için hint kullandık.Ve oluşturulan bütün degerlere id atanmıştır.
Activityden Cagırma
package com.example.enespecenek.gelecegiyazanlar;
import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText edt1=(EditText) findViewById(R.id.edt1);//oluşturulan id degeri ile tanımlattık.Eger id tanımlamazsak xml sayafasındaki nesneler görünmez.
EditText edt2=(EditText) findViewById(R.id.edt2);
EditText edt3=(EditText) findViewById(R.id.edt3);
((Button) findViewById(R.id.btn1)).setOnClickListener(new View.OnClickListener() {
@Override//Tek bir buton oldugu için boyle yapıldı.setOnclıckListener methodu içinde OnClickListener degişkeni kullanılmıştır.
public void onClick(View v) {
EditText edt4=(EditText) findViewById(R.id.edt4);
}
});
}
}