İşte benim düzen kodum;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:text="@string/welcome"
android:id="@+id/TextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView>
<LinearLayout android:id="@+id/LinearLayout"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom">
<EditText android:id="@+id/EditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</EditText>
<Button android:text="@string/label_submit_button"
android:id="@+id/Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
</LinearLayout>
Bunun nasıl göründüğü solda ve nasıl görünmesini istediğim sağda.
Bariz cevap TextView'i yükseklikte fill_parent olarak ayarlamaktır, ancak bu düğme veya giriş alanı için yer kalmamasına neden olur.
Esasen sorun şu ki, gönder düğmesinin ve metin girişinin altta sabit bir yükseklikte olmasını ve metin görünümünün alanın geri kalanını doldurmasını istiyorum. Benzer şekilde, yatay doğrusal düzende gönder düğmesinin içeriğini sarmasını ve metin girişinin alanın geri kalanını doldurmasını istiyorum.
Doğrusal bir düzendeki ilk öğeye fill_parent komutu verilirse, tam olarak bunu yapar ve diğer öğeler için yer bırakmaz. Doğrusal bir düzendeki ilk öğenin, düzendeki diğer öğeler için gereken minimum alan dışında tüm alanı doldurmasını nasıl sağlarım?
Göreceli düzenler gerçekten de çözümdü:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="@string/welcome"
android:id="@+id/TextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
</TextView>
<RelativeLayout
android:id="@+id/InnerRelativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:text="@string/label_submit_button"
android:id="@+id/Button"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
<EditText
android:id="@+id/EditText"
android:layout_width="fill_parent"
android:layout_toLeftOf="@id/Button"
android:layout_height="wrap_content">
</EditText>
</RelativeLayout>
</RelativeLayout>
Bunu yapmanın modern yolu bir ConstraintLayout'e sahip olmak ve görünümün alt kısmını ConstraintLayout'un alt kısmına app:layout_constraintBottom_toBottomOf="parent"
ile kısıtlamaktır.
Aşağıdaki örnek, ekranın sonuna ve altına hizalanacak bir FloatingActionButton oluşturur.
<android.support.constraint.ConstraintLayout
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_height="match_parent"
android:layout_width="match_parent">
<android.support.design.widget.FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</android.support.constraint.ConstraintLayout>
Referans olması için eski cevabımı saklayacağım.
ConstraintLayout'un kullanılmaya başlanmasından önce cevap relative layout idi.
Tüm ekranı dolduran göreli bir düzeniniz varsa, düğmeyi ekranın altına taşımak için android:layout_alignParentBottom
kullanabilmeniz gerekir.
Alttaki görünümleriniz göreli bir düzende gösterilmiyorsa, belki de üstteki düzen tüm alanı kaplıyordur. Bu durumda, altta olması gereken görünümü düzen dosyanızda ilk sıraya koyabilir ve düzenin geri kalanını android:layout_above
ile görünümlerin üzerinde konumlandırabilirsiniz. Bu, alttaki görünümün ihtiyaç duyduğu kadar yer kaplamasını ve yerleşimin geri kalanının ekranın geri kalanını doldurabilmesini sağlar.
Bir ScrollView
de bu işe yaramaz, çünkü RelativeLayout
sayfanın altındaki ScrollView
de ne varsa onunla çakışır.
Dinamik olarak esneyen bir FrameLayout
kullanarak düzelttim:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fillViewport="true">
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
<!-- content goes here -->
<!-- stretching frame layout, using layout_weight -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</FrameLayout>
<!-- content fixated to the bottom of the screen -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!-- your bottom content -->
</LinearLayout>
</LinearLayout>
</ScrollView>
İkinci göreceli' düzeni birincinin içine yerleştirmenize bile gerek yoktur. Sadece *Button* ve *EditText* içinde
android:layout_alignParentBottom="true"` kullanın.