Merhaba arkadaşlar bu yazıda örneklerle LinearLayout kullanımı üzerinde duracağız.LinearLayout;bileşenleri yatay veya dikey olarak düzenleyen ortak bir düzendir.Örnek uygulamamızda 3 buton kullanıp bunları yatay ve dikey olarak yerleştireceğiz.
1-LinearLayout-Yatay Düzen
res/layout/activity_main.xml veya res/layout/main.xml dosyamızı düzenlemek için açıyoruz.Görsel arayüzden veya direk xml dosyasından düzenleme yapabiliriz.LinearLayout oluşturuyoruz ve içerisine 3 adet buton ekliyoruz.Butonları, buton1,buton2,buton3 olarak adlandırdım. Görsellere baktığımızda dikkatimizi çekecek bir ayrıntıyı belirtiyim.Kodlamada da fark edeceğiniz android:layout_weight=”1″ değeri yatay düzende eğer tek butona atanmışsa, standart buton genişliğini bırakıp kalan alanı kaplıyor eğer bu değeri tüm butonlara verirseniz yatay düzeni eşit olarak 3 buton için ayırmış olacaksınız.
[codesyntax lang="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=”match_parent”
tools:context=”.MainActivity” >
<LinearLayout
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:orientation=”horizontal” >
<Button
android:id=”@+id/button1″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Buton 1″
android:layout_weight=”1″/>
<Button
android:id=”@+id/button2″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Buton 2″
android:layout_weight=”1″ />
<Button
android:id=”@+id/button3″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Buton 3″
android:layout_weight=”1″/>
</LinearLayout>
</RelativeLayout>
[/codesyntax]
2-LinearLayout Dikey Düzen(Vertical)
res/layout/activity_main.xml veya res/layout/main.xml dosyamızı düzenlemek için açıyoruz.Yatay düzende olduğu gibi android:layout_weight=”1″ değerimiz dikey düzenimizde butonların eşit yer kaplamasını sağlıyor.
[codesyntax lang="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=”match_parent”
tools:context=”.MainActivity” >
<LinearLayout
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:orientation=”vertical” >
<Button
android:id=”@+id/button1″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Buton 1″
android:layout_weight=”1″ />
<Button
android:id=”@+id/button2″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Buton 2″
android:layout_weight=”1″ />
<Button
android:id=”@+id/button3″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Buton 3″
android:layout_weight=”1″/>
</LinearLayout>
</RelativeLayout>
[/codesyntax]




