17 Aralık 2017 Pazar

LinearLayout Sınıfı

Giriş
Eğer orientation horizontal ise bileşenlerin aynı satıra yerleşmesini sağlar.
Eğer orientation vertical ise bileşenlerin aynı sütuna yerleşmesini sağlar.

constructor
Şöyle yaparız.
LinearLayout layout = new LinearLayout(getActivity());
addView metodu
Şöyle yaparız. Birden fazla view eklenebilir.
//Add Category Title
 TextView title = new TextView(getActivity());
title.setLayoutParams(
  new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CON‌​TENT,
                                LinearLayout.LayoutParams.WRAP_CONTENT));
title.setPadding(10,0,0,0);
...
layout.addView(title);
setLayoutParams
Şöyle yaparız.
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams
(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(15, 5, 5, 10);
layout.setLayoutParams(params);
layout_weight
Aynı satıra iki tane daha LinearLayout yerleştirip büyüklüklerini oranlamak için şöyle yaparız.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:padding="15dp"
    android:weightSum="1">
      <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight=".75" // For First layout to 3/4
        android:background="@color/colorPrimary"
        android:gravity="left|center"
        android:orientation="vertical">
            //First Layout content Here
        </LinearLayout>

        <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight=".25" // For Second layout to rest of screen
        android:background="@color/colorAccent"
        android:gravity="center"
        android:orientation="vertical">
               //Second Layout Content Here
           </LinearLayout>
</LinearLayout>
orientation
Dikey olması için şöyle yaparız.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="15dp"
android:paddingRight="15dp">
...
</LinearLayout>

Hiç yorum yok:

Yorum Gönder