我正在使用这段代码。但是,当我单击 EditText 打开键盘时,视图并未完全打开。为什么视图没有一路上升,EditText隐藏在键盘后面
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
android:background="@drawable/main_bg"
android:id="@+id/mainLayout"
android:focusableInTouchMode="true"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"
android:id="@+id/topBar"
android:background="@drawable/top_bar_bg"
>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal|bottom"
android:layout_centerInParent="true"
>
<ImageView
android:id="@+id/loadingAnimationImg"
android:layout_height="35dp"
android:layout_width="35dp"
android:adjustViewBounds="true"
android:contentDescription="@null"
android:background="@drawable/img05"/>
<ImageView
android:layout_marginBottom="5dp"
android:layout_height="wrap_content"
android:layout_width="120dp"
android:adjustViewBounds="true"
android:contentDescription="@null"
android:src="@drawable/simple_logo"/>
</LinearLayout>
</RelativeLayout>
<GridView
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="300dp"
android:id="@+id/gridView"
android:numColumns="5"
android:verticalSpacing="5dp" />
<TextView
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textColor="@android:color/white"
android:text="@string/hashtagText"
/>
<com.trib.devicebee.custom.FlowLayout
android:id="@+id/flowLayout"
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<EditText
android:layout_margin="10dp"
android:id="@+id/hashTagsText"
android:hint=""
android:inputType="textFilter"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
/>
<Button
android:id="@+id/goAheadBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/go_ahead_btn"
android:layout_margin="10dp"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我想出的最好的解决方案是将所有内容都放在滚动视图中。
现在在清单中
<activity
android:name="MyActivity"
android:windowSoftInputMode="adjustResize">
</activity>
Run Code Online (Sandbox Code Playgroud)现在在您想要聚焦的 editText 上使用 onfocusChangeListener
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
if (b){
scrollView.smoothScrollTo(0,editText.getBottom()+5);
}
}
});
Run Code Online (Sandbox Code Playgroud)我们就完成了。
| 归档时间: |
|
| 查看次数: |
4159 次 |
| 最近记录: |