Tuesday, March 6, 2018

Android Layout Yüzdeleme

Merhaba Arkadaşlar,

Bugün Android Projelerinde olmazsa olmaz ekran tasarımının bir parçası olan ekranı yüzdeliklere ayırmayı anlatacağım. Aslında "layout_weight " kodunu kullanacağız. Layout'un hangi bölümünün  ne kadar ağırlıkta kalmasını istediğimizi belirliyoruz.

Android Studioda sayfa tasarımı yaparken bazen sayfaları belli dilimlere ayırmak, sayfa tasarımını daha kolay yapmamızı sağlayabilir. Android Studioda Sayfa tasarımı yaparken;

.xlm kısmındaki layout sayfamızı açarak gerekli olan araçları sayfamıza ekliyoruz.İlk örneğimiz vertical olarak hazırlanmıştır.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?xml version="1.0" encoding="utf-8"?>
<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:weightSum="100"
    tools:context="com.hande.umut.buttontiklama.MainActivity">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="50"
        android:orientation="vertical">

        <TextView
            android:id="@+id/text1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#7AC5CD"
            android:fontFamily="sans-serif"
            android:gravity="center"
            android:text="Yüzde50"
            android:textAlignment="center"
            android:textColor="#000000"
            android:textStyle="italic" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="20"
        android:orientation="vertical">

        <TextView
            android:id="@+id/text2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#76EE00"
            android:fontFamily="sans-serif"
            android:gravity="center"
            android:text="Yüzde 20"
            android:textAlignment="center"
            android:textColor="#000000"
            android:textStyle="italic" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="30"
        android:orientation="vertical">


        <TextView
            android:id="@+id/text3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#8A2BE2"
            android:fontFamily="sans-serif"
            android:gravity="center"
            android:text="Yüzde 30"
            android:textAlignment="center"
            android:textColor="#000000"
            android:textStyle="italic" />
    </LinearLayout>
</LinearLayout>

Dikey olarak hazırlanmış örneğimizde aşağıdaki gibidir;





 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?xml version="1.0" encoding="utf-8"?>
<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:weightSum="100"
    tools:context="com.hande.umut.buttontiklama.MainActivity">


        <TextView
            android:id="@+id/text1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#7AC5CD"
            android:fontFamily="sans-serif"
            android:gravity="center"
            android:layout_weight="50"
            android:text="Yüzde50"
            android:textAlignment="center"
            android:textColor="#000000"
            android:textStyle="italic" />

        <TextView
            android:id="@+id/text2"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#76EE00"
            android:fontFamily="sans-serif"
            android:gravity="center"
            android:layout_weight="20"
            android:text="Yüzde 20"
            android:textAlignment="center"
            android:textColor="#000000"
            android:textStyle="italic" />


        <TextView
            android:id="@+id/text3"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="30"
            android:background="#8A2BE2"
            android:fontFamily="sans-serif"
            android:gravity="center"
            android:text="Yüzde 30"
            android:textAlignment="center"
            android:textColor="#000000"
            android:textStyle="italic" />

</LinearLayout>

No comments:

Post a Comment