使用带有PercentageLayout的键盘时,java视图会缩小
我有两个不同的XML文件。一个是注册。xml另一个聊天。xml,都是用PercentageLayout库构建的
注册。xml非常有效-打开键盘不会改变任何视图。
然而,在聊天中。xml每当我打开键盘时,视图就会缩小或离开屏幕,我不知道为什么,因为我几乎以相同的方式构建了它们,只是我怀疑,因为我使用了ScrollView
,所以会发生这种情况
有问题的布局chat.xml
:
<?xml version="1.0" encoding="utf-8"?>
<安卓.support.percent.PercentRelativeLayout
xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:app="http://schemas.安卓.com/apk/res-auto"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent">
<!-- top -->
<LinearLayout
安卓:id="@+id/top"
安卓:layout_width="0dp"
安卓:layout_height="0dp"
app:layout_widthPercent="100%"
app:layout_heightPercent="8%"
安卓:background="#075607"
安卓:orientation="vertical">
<TextView
安卓:layout_width="wrap_content"
安卓:layout_height="match_parent"
安卓:textColor="#acddf4"
安卓:textSize="20sp"
安卓:text="jfioewjfoiewjfoi"
安卓:gravity="center"
安卓:layout_gravity="center_horizontal|center_vertical" />
</LinearLayout>
<!-- Mid -->
<LinearLayout
安卓:id="@+id/mid"
安卓:layout_below="@+id/top"
安卓:layout_width="0dp"
安卓:layout_height="0dp"
app:layout_widthPercent="100%"
app:layout_heightPercent="84%"
安卓:background="#b1b7b3"
安卓:orientation="vertical">
<ScrollView
安卓:id="@+id/scroller"
安卓:layout_width="match_parent"
安卓:layout_height="fill_parent"
安卓:background="@drawable/chat_bg" >
<LinearLayout
安卓:id="@+id/chatWindowContainer"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>
<!-- Bottom -->
<LinearLayout
安卓:id="@+id/bottom"
安卓:layout_below="@+id/mid"
安卓:layout_width="0dp"
安卓:layout_height="0dp"
app:layout_widthPercent="100%"
app:layout_heightPercent="8%"
安卓:background="#000000"
安卓:orientation="horizontal">
<EditText
安卓:id="@+id/etMessage"
安卓:layout_width="wrap_content"
安卓:layout_height="match_parent"
安卓:layout_weight="1"
安卓:ems="10"
安卓:paddingLeft="5dp"
安卓:background="@drawable/text"
安卓:imeOptions="actionNone"
安卓:inputType="textMultiLine"
安卓:singleLine="false" />
<Button
安卓:id="@+id/bSendMessage"
安卓:layout_width="40dp"
安卓:layout_height="match_parent"
安卓:background="@drawable/ic_send"
安卓:layout_gravity="right" />
</LinearLayout>
以及工作布局signup.xml
:
<LinearLayout
安卓:id="@+id/title"
安卓:layout_height="0dp"
安卓:layout_width="0dp"
app:layout_heightPercent="15%"
app:layout_widthPercent="100%">
<ImageView
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:src="@drawable/signup"/>
</LinearLayout>
<LinearLayout
安卓:id="@+id/mid"
安卓:orientation="vertical"
安卓:layout_height="0dp"
安卓:layout_width="0dp"
安卓:layout_below="@+id/title"
app:layout_heightPercent="35%"
app:layout_widthPercent="100%"
安卓:baselineAligned="true">
<!-- Username -->
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="30dp"
安卓:orientation="horizontal"
app:layout_heightPercent="20%"
app:layout_widthPercent="20%">
<ImageView
安卓:layout_width="35dp"
安卓:layout_height="wrap_content"
安卓:src="@drawable/person" />
<EditText
安卓:id="@+id/etUsername_signup"
安卓:layout_width="0dp"
安卓:layout_height="match_parent"
安卓:ems="10"
安卓:inputType="text"
安卓:text="test"
安卓:textColor="#000000"
安卓:paddingLeft="5dp"
安卓:layout_weight="0.1"
安卓:background="@drawable/text">
<requestFocus />
</EditText>
</LinearLayout>
<!-- Email -->
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="30dp"
安卓:orientation="horizontal"
app:layout_heightPercent="20%"
app:layout_widthPercent="20%">
<ImageView
安卓:layout_width="35dp"
安卓:layout_height="wrap_content"
安卓:src="@drawable/email" />
<EditText
安卓:id="@+id/etEmail_signup"
安卓:layout_width="0dp"
安卓:layout_height="match_parent"
安卓:ems="10"
安卓:inputType="textEmailAddress"
安卓:text="email@address.com"
安卓:textColor="#000000"
安卓:paddingLeft="5dp"
安卓:layout_weight="0.1"
安卓:background="@drawable/text"/>
</LinearLayout>
<!-- Password1 -->
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="30dp"
安卓:orientation="horizontal"
app:layout_heightPercent="20%"
app:layout_widthPercent="20%">
<ImageView
安卓:layout_width="35dp"
安卓:layout_height="wrap_content"
安卓:src="@drawable/password" />
<EditText
安卓:id="@+id/etPassword1_signup"
安卓:layout_width="0dp"
安卓:layout_height="match_parent"
安卓:ems="10"
安卓:inputType="textPassword"
安卓:text="pass"
安卓:textColor="#000000"
安卓:paddingLeft="5dp"
安卓:layout_weight="0.1"
安卓:background="@drawable/text"/>
</LinearLayout>
<!-- Password2 -->
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="30dp"
安卓:orientation="horizontal"
app:layout_heightPercent="20%"
app:layout_widthPercent="20%">
<ImageView
安卓:layout_width="35dp"
安卓:layout_height="wrap_content"
安卓:src="@drawable/password" />
<EditText
安卓:id="@+id/etPassword2_signup"
安卓:layout_width="0dp"
安卓:layout_height="match_parent"
安卓:ems="10"
安卓:inputType="textPassword"
安卓:text="pass"
安卓:textColor="#000000"
安卓:paddingLeft="5dp"
安卓:layout_weight="0.1"
安卓:background="@drawable/text"/>
</LinearLayout>
<!-- Spinner and RadioGroup-->
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:orientation="horizontal"
安卓:gravity="center">
<Spinner
安卓:layout_width="100dp"
安卓:layout_height="match_parent"
安卓:id="@+id/spinner"
安卓:layout_gravity="center" />
<RadioGroup
安卓:id="@+id/rgRadius"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content">
<RadioButton
安卓:id="@+id/radio0"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:checked="true"
安卓:text="Kilometer" />
<RadioButton
安卓:id="@+id/radio1"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:text="Mile" />
</RadioGroup>
</LinearLayout>
</LinearLayout>
<!-- Image -->
<LinearLayout
安卓:id="@+id/image"
安卓:orientation="vertical"
安卓:layout_height="0dp"
安卓:layout_width="0dp"
安卓:layout_below="@+id/mid"
app:layout_heightPercent="40%"
app:layout_widthPercent="100%"
安卓:baselineAligned="true">
<ImageView
安卓:id="@+id/imgProfile"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:src="@drawable/faceless" />
</LinearLayout>
<!-- Button -->
<LinearLayout
安卓:layout_width="0dp"
安卓:layout_height="0dp"
app:layout_heightPercent="10%"
app:layout_widthPercent="100%"
安卓:orientation="vertical"
安卓:layout_below="@id/image">
<Button
安卓:layout_width="150dp"
安卓:layout_height="wrap_content"
安卓:id="@+id/bSignup"
安卓:layout_gravity="center|bottom"
安卓:background="@drawable/button_send" />
</LinearLayout>
# 1 楼答案
使用相对布局解决缩小布局问题我测试了以下布局
添加以下带有活动标记的条目:
android:windowSoftInputMode="adjustResize"
你的布局呢