Этот вопрос уже beeen спросил несколько лет назад и «Secret Andro Geni» имеет хорошее базовое объяснение, а «tir38» также сделал хорошую попытку полного решения, но, увы, здесь нет полного решения. Я потратить пару часов выяснить вещи, и вот мое полное решение с подробным объяснением на дне:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/mainLayout"
android:layout_alignParentTop="true"
android:id="@+id/headerLayout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView1"
android:text="facebook"
android:textStyle="bold"
android:ellipsize="marquee"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:id="@+id/mainLayout"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText1"
android:ems="10"
android:hint="Email or Phone"
android:inputType="textVisiblePassword">
<requestFocus />
</EditText>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:id="@+id/editText2"
android:ems="10"
android:hint="Password"
android:inputType="textPassword" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:id="@+id/button1"
android:text="Log In"
android:onClick="login" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@+id/mainLayout"
android:id="@+id/footerLayout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView2"
android:text="Sign Up for Facebook"
android:layout_centerHorizontal="true"
android:layout_alignBottom="@+id/helpButton"
android:ellipsize="marquee"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:id="@+id/helpButton"
android:text="\?"
android:onClick="help" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
И в AndroidManifest.xml, не забудьте установить:
android:windowSoftInputMode="adjustResize"
на ярлыке <activity>
, который вы хотите, такой макет.
Мысль:
Я понял, что RelativeLayout
являются макетами, которые охватывают через все доступное пространство, а затем изменение размеров, когда клавиатура всплывает.
И LinearLayout
- это макеты, которые не изменяются в процессе изменения размера.
Именно поэтому вам необходимо иметь 1 RelativeLayout
сразу после ScrollView
, чтобы охватить все доступное пространство экрана. И вам нужно иметь LinearLayout
внутри RelativeLayout
, иначе ваши внутренности будут раздавлены, когда произойдет изменение размера. Хорошим примером является «headerLayout». Если бы не было LinearLayout
внутри, то RelativeLayout
текст «facebook» будет раздавлен и не будет отображаться.
В «facebook» для входа изображений, размещенных в этом вопросе я также заметил, что вся Войти часть (mainLayout) центрируется по вертикали по отношению ко всему экрану, следовательно атрибут:
android:layout_centerVertical="true"
на LinearLayout
макет. И поскольку mainLayout находится внутри LinearLayout
, это означает, что эта часть не будет изменена (снова посмотрите на картинку).
+1 Это просто? Какие-либо дополнительные условия? Каким было изображение, о котором вы писали? – Roylee
друзья, чтобы показать alignparentbottom = "true", если экран не настроен правильно ..hence я разместил это изображение друга –
Очень хороший ответ действительно. Спасибо за помощь, приятель. Рад, что ты пришел. – Roylee