Home Android Razvoj aplikacija Android wrap_content i fill_parent primjer

Android wrap_content i fill_parent primjer

programiranje Android aplikacija
Android razvoj aplikacija

Kod programiranja Android aplikacija uvijek ćete koristiti ove 2 stvari: wrap_content i match_parent. S tim, da se match_parent prije API 8 zvao fill_parent.

Wrap_content i fill_parent su veoma bitni parametri u Android programiranju jer oni vam omogućavaju podešavanje izgleda vaše Android aplikacije. Ispod se nalazi nekoliko primjera, primjene ova dva parametra.

Ukoliko niste pogledajte kako započeti programiranje Android aplikacija, a takođe možete pregledati i “Zdravo, Svijete” tutorijal.

1.wrap_content

Kada postavite wrap_content i za width (širina) i height (visina), onda će vam se napraviti dugme dovoljne veličine da ispiše tekst koji ste mu dodijelili, i to u ovom slučaju droid.ba.

[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" >

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Droid.ba" />

</RelativeLayout>

[/xml]

wrap_content
wrap_content

2. fill_parent – width

Kada postavite vrijednost fill_parent za parametar width, dobijte to da dugme popuni prazan prostor u širinu (width) koju ima “roditelj”, a to je u ovom slučaju RelativeLayout.

[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" >

<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Droid.ba" />

</RelativeLayout>

[/xml]

fill_parent - width
fill_parent – width

3. fill_parent – height

U ovom slučaju, dugme popunjava prostor u visinu (height) koju ima roditelj RelativeLayout.

[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" >

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Droid.ba" />

</RelativeLayout>

[/xml]

fill_parent – height
fill_parent – height

4. fill_parent – width, height

Kada postavimo vrijednost fill_parent i za width i height atribut, dobijemo da dugme zauzme prostor cijelog prostora koji je namijenjen roditelju RelativeLayout, u ovom slučaju.

[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" >

<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Droid.ba" />

</RelativeLayout>

[/xml]

fill_parent – width, height
fill_parent – width, height

Želite više uputstava za programiranje Android aplikacija?