【发布时间】:2016-08-17 16:40:18
【问题描述】:
我有 2 个不同的 XML 文件。一个是 signup.xml,另一个是 chat.xml,两者都是用 PercentageLayout 库构建的。
signup.xml 效果很好 - 打开键盘不会改变任何视图。 但是,在 chat.xml 中,每当我弹出键盘时,视图都会缩小或超出屏幕,我不知道为什么,因为我几乎以相同的方式构造它们,只是我怀疑是因为我使用 @ 987654321@ 发生这种情况。
有问题的布局,chat.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- top -->
<LinearLayout
android:id="@+id/top"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_widthPercent="100%"
app:layout_heightPercent="8%"
android:background="#075607"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textColor="#acddf4"
android:textSize="20sp"
android:text="jfioewjfoiewjfoi"
android:gravity="center"
android:layout_gravity="center_horizontal|center_vertical" />
</LinearLayout>
<!-- Mid -->
<LinearLayout
android:id="@+id/mid"
android:layout_below="@+id/top"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_widthPercent="100%"
app:layout_heightPercent="84%"
android:background="#b1b7b3"
android:orientation="vertical">
<ScrollView
android:id="@+id/scroller"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="@drawable/chat_bg" >
<LinearLayout
android:id="@+id/chatWindowContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>
<!-- Bottom -->
<LinearLayout
android:id="@+id/bottom"
android:layout_below="@+id/mid"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_widthPercent="100%"
app:layout_heightPercent="8%"
android:background="#000000"
android:orientation="horizontal">
<EditText
android:id="@+id/etMessage"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:ems="10"
android:paddingLeft="5dp"
android:background="@drawable/text"
android:imeOptions="actionNone"
android:inputType="textMultiLine"
android:singleLine="false" />
<Button
android:id="@+id/bSendMessage"
android:layout_width="40dp"
android:layout_height="match_parent"
android:background="@drawable/ic_send"
android:layout_gravity="right" />
</LinearLayout>
还有工作布局,signup.xml:
<LinearLayout
android:id="@+id/title"
android:layout_height="0dp"
android:layout_width="0dp"
app:layout_heightPercent="15%"
app:layout_widthPercent="100%">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/signup"/>
</LinearLayout>
<LinearLayout
android:id="@+id/mid"
android:orientation="vertical"
android:layout_height="0dp"
android:layout_width="0dp"
android:layout_below="@+id/title"
app:layout_heightPercent="35%"
app:layout_widthPercent="100%"
android:baselineAligned="true">
<!-- Username -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal"
app:layout_heightPercent="20%"
app:layout_widthPercent="20%">
<ImageView
android:layout_width="35dp"
android:layout_height="wrap_content"
android:src="@drawable/person" />
<EditText
android:id="@+id/etUsername_signup"
android:layout_width="0dp"
android:layout_height="match_parent"
android:ems="10"
android:inputType="text"
android:text="test"
android:textColor="#000000"
android:paddingLeft="5dp"
android:layout_weight="0.1"
android:background="@drawable/text">
<requestFocus />
</EditText>
</LinearLayout>
<!-- Email -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal"
app:layout_heightPercent="20%"
app:layout_widthPercent="20%">
<ImageView
android:layout_width="35dp"
android:layout_height="wrap_content"
android:src="@drawable/email" />
<EditText
android:id="@+id/etEmail_signup"
android:layout_width="0dp"
android:layout_height="match_parent"
android:ems="10"
android:inputType="textEmailAddress"
android:text="email@address.com"
android:textColor="#000000"
android:paddingLeft="5dp"
android:layout_weight="0.1"
android:background="@drawable/text"/>
</LinearLayout>
<!-- Password1 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal"
app:layout_heightPercent="20%"
app:layout_widthPercent="20%">
<ImageView
android:layout_width="35dp"
android:layout_height="wrap_content"
android:src="@drawable/password" />
<EditText
android:id="@+id/etPassword1_signup"
android:layout_width="0dp"
android:layout_height="match_parent"
android:ems="10"
android:inputType="textPassword"
android:text="pass"
android:textColor="#000000"
android:paddingLeft="5dp"
android:layout_weight="0.1"
android:background="@drawable/text"/>
</LinearLayout>
<!-- Password2 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal"
app:layout_heightPercent="20%"
app:layout_widthPercent="20%">
<ImageView
android:layout_width="35dp"
android:layout_height="wrap_content"
android:src="@drawable/password" />
<EditText
android:id="@+id/etPassword2_signup"
android:layout_width="0dp"
android:layout_height="match_parent"
android:ems="10"
android:inputType="textPassword"
android:text="pass"
android:textColor="#000000"
android:paddingLeft="5dp"
android:layout_weight="0.1"
android:background="@drawable/text"/>
</LinearLayout>
<!-- Spinner and RadioGroup-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<Spinner
android:layout_width="100dp"
android:layout_height="match_parent"
android:id="@+id/spinner"
android:layout_gravity="center" />
<RadioGroup
android:id="@+id/rgRadius"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Kilometer" />
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mile" />
</RadioGroup>
</LinearLayout>
</LinearLayout>
<!-- Image -->
<LinearLayout
android:id="@+id/image"
android:orientation="vertical"
android:layout_height="0dp"
android:layout_width="0dp"
android:layout_below="@+id/mid"
app:layout_heightPercent="40%"
app:layout_widthPercent="100%"
android:baselineAligned="true">
<ImageView
android:id="@+id/imgProfile"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/faceless" />
</LinearLayout>
<!-- Button -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_heightPercent="10%"
app:layout_widthPercent="100%"
android:orientation="vertical"
android:layout_below="@id/image">
<Button
android:layout_width="150dp"
android:layout_height="wrap_content"
android:id="@+id/bSignup"
android:layout_gravity="center|bottom"
android:background="@drawable/button_send" />
</LinearLayout>
【问题讨论】:
-
在 manifest.xml 中使用带有活动的 softinputmod?
-
我不在任何地方使用软输入法
-
嘿,我也遇到了同样的问题,你找到解决办法了吗?
-
运气好吗?我也面临同样的问题
标签: java android xml user-interface