我有以下.xml
文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_100"
android:orientation="vertical"
android:weightSum="4">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:id="@+id/login_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/welcome_bottom_margin"
android:layout_marginTop="@dimen/login_logo_margin_top"
android:theme="@style/ThemeOverlay.MyTitleText"
app:srcCompat="@mipmap/ic_launcher" />
<TextView
android:id="@+id/status"
style="@style/ThemeOverlay.MyTextDetail"
android:text="@string/signed_out" />
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/grey_300"
android:gravity="center_vertical">
<LinearLayout
android:id="@+id/email_password_fields"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="16dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:paddingRight="16dp">
<EditText
android:id="@+id/field_email"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/hint_email"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/field_password"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/hint_password"
android:inputType="textPassword" />
</LinearLayout>
<LinearLayout
android:id="@+id/email_password_buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/email_password_fields"
android:orientation="horizontal"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<Button
android:id="@+id/email_sign_in_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/sign_in"
android:theme="@style/ThemeOverlay.MyDarkButton" />
<Button
android:id="@+id/email_create_account_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/create_account"
android:theme="@style/ThemeOverlay.MyDarkButton" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
看起来像this。但是当我打开键盘时,它隐藏了RelativeLayout
的80%。
如何将布局移到键盘上方?
我找到了各种各样的答案,但似乎都没有。
编辑:
即使在我的android:windowSoftInputMode="adjustResize"
中添加Manifest
之后也是如此:
<activity android:name=".MainActivity"
android:windowSoftInputMode="adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>`
我得到以下结果:
答案 0 :(得分:2)
在AndroidManifest.xml中为您的活动设置softInputMode
<activity
android:windowSoftInputMode="adjustResize"
android:name=".MyActivity"
/>
用以下代码替换xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:id="@+id/login_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/welcome_bottom_margin"
android:layout_marginTop="@dimen/login_logo_margin_top"
android:theme="@style/ThemeOverlay.MyTitleText"
app:srcCompat="@mipmap/ic_launcher" />
<TextView
android:id="@+id/status"
style="@style/ThemeOverlay.MyTextDetail"
android:text="@string/signed_out" />
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:background="@color/grey_300"
android:gravity="center_vertical">
<LinearLayout
android:id="@+id/email_password_fields"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="16dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:paddingRight="16dp">
<EditText
android:id="@+id/field_email"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/hint_email"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/field_password"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/hint_password"
android:inputType="textPassword" />
</LinearLayout>
<LinearLayout
android:id="@+id/email_password_buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/email_password_fields"
android:orientation="horizontal"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<Button
android:id="@+id/email_sign_in_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/sign_in"
android:theme="@style/ThemeOverlay.MyDarkButton" />
<Button
android:id="@+id/email_create_account_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/create_account"
android:theme="@style/ThemeOverlay.MyDarkButton" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</ScrollView>
答案 1 :(得分:1)
只需在您的活动中添加以下代码:
<activity
android:windowSoftInputMode="adjustResize"
android:name=".youractivity"
/>
也许帮助你,试试这些代码。更多信息:How to adjust layout when soft keyboard appears
答案 2 :(得分:0)
添加
declare @t1 table
(
IDCol char(5),
Col1 INT,
Col2 INT,
Col3 INT
)
Insert into @t1 values ('ID1', 3 , 3 , 1000);
Insert into @t1 values ('ID1', 6 , 6 , 1000);
Insert into @t1 values ('ID1', 6 , 4 , 1000);
Insert into @t1 values ('ID2', 11 , 3 , 1000);
Insert into @t1 values ('ID2', 6 , 6 , 1000);
Select * from
(
Select t1.IDCol, t1.Col1,
Lead(t1.Col2) Over (Partition by t1.IDCol Order By t1.IDCol) Col2,
t1.Col3 From
(
Select IDCol, Col1, Col2, Col3,
ROW_NUMBER() over(partition by IDCol order by IDCol) as RowFlg
from @t1
) t1,
(
Select IDCol, Min(RowFlg) Col1MinVal, Max(RowFlg) Col2MaxVal from
(
Select IDCol, ROW_NUMBER() over(partition by IDCol order by IDCol) as RowFlg from @t1
) z
Group By IDCol
) x
Where t1.IDCol = x.IDCol AND (t1.RowFlg = x.Col1MinVal OR t1.RowFlg = x.Col2MaxVal)
) main
Where Col2 is not null
在活动代码
中的清单中答案 3 :(得分:0)
使用<activity android:windowSoftInputMode="adjustResize"> </activity>
或<activity android:windowSoftInputMode="adjustPan"> </activity>
,您可以在此处看到差异Difference between adjustResize and adjustPan in android?