我一直在寻找这个问题的解决方案,但我找不到任何可以解决我的问题.
我使用RelativeLayout作为我的主要布局,我的页脚也是RelativeLayout,我在互联网上找到了这些配置:
机器人:windowSoftInputMode = “adjustPan | adjustResize”
它适用于页脚保持固定,但我的滚动不起作用,这是我的主要问题,我能做些什么来解决它?
我的布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:focusable="true"
android:fitsSystemWindows="true"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollView1"
android:fillViewport="true"
android:isScrollContainer="true"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/ttvp1"
style="@style/ttvPersonalizado"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/p1" />
<TextView
android:id="@+id/ttvp2"
style="@style/ttvPersonalizadoDireito"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/p2" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/edtP1"
style="@style/edtPersonalizado"
android:maxLength="5"
android:layout_height="wrap_content"
android:background="@drawable/edit_text_design"
android:ems="10"
android:inputType="numberDecimal" >
</EditText>
<EditText
android:id="@+id/edtP2"
style="@style/edtPersonalizado"
android:maxLength="5"
android:layout_height="wrap_content"
android:background="@drawable/edit_text_design"
android:ems="10"
android:inputType="numberDecimal" />
</LinearLayout>
<TextView
android:id="@+id/ttvpim"
style="@style/ttvPersonalizado"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/pip3" />
<EditText
android:id="@+id/edtPiP3"
style="@style/edtPersonalizado"
android:maxLength="5"
android:layout_height="wrap_content"
android:background="@drawable/edit_text_design"
android:inputType="numberDecimal" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/ttvExame"
style="@style/ttvPersonalizado"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="18dp"
android:text="@string/notaExame" />
<CheckBox
android:id="@+id/chkExame"
style="@style/chkPersonalizado"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:text="@string/exame" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/edtExame"
style="@style/edtPersonalizado"
android:maxLength="5"
android:layout_height="wrap_content"
android:background="@drawable/edit_text_design"
android:ems="10"
android:enabled="false"
android:inputType="numberDecimal"
android:width="125dp" />
<CheckBox
android:id="@+id/chkPersonalizado"
style="@style/chkPersonalizado"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tecnologo" />
</LinearLayout>
<TextView
style="@style/ttvPersonalizado"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/mediaFinal" />
<EditText
android:id="@+id/edtMedia"
style="@style/edtPersonalizado"
android:maxLength="5"
android:layout_height="wrap_content"
android:background="@drawable/edit_text_design"
android:enabled="false"
android:inputType="numberDecimal" />
<TextView
android:id="@+id/ttvStatus"
style="@style/ttvPersonalizado"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageButton
android:id="@+id/btnGerarMedia"
style="@style/btnMedio"
android:background="@drawable/shapebutton"
android:contentDescription="@string/gerarMedia"
android:src="@drawable/icone_calculadora"
android:text="@string/gerarMedia" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dip"
android:layout_alignParentBottom="true"
android:background="@drawable/background_footer"
android:orientation="vertical" >
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="fill_parent" />
</RelativeLayout>
</RelativeLayout>
我在AndroidManifest中的活动配置:
<activity
android:name="br.com.media_universidades.visao.MediaCalculoActivity"
android:icon="@drawable/ic_launcher"
android:label="@string/umc" android:windowSoftInputMode="adjustPan|adjustResize"/>
先感谢您.
最佳答案 取决于您使用的Android版本以及您的布局将有不同的解决方案:
<activity
android:name="br.com.media_universidades.visao.MediaCalculoActivity"
android:icon="@drawable/ic_launcher"
android:label="@string/umc"
android:windowSoftInputMode="adjustResize">
编辑:修改上面的代码作为我写的以前的答案是使用这个
android:windowSoftInputMode="stateVisible|adjustResize"/>
但有时你必须使用onCreate()方法中的代码强制它:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
这是一个修复,这是doc.
The setting must be one of the values listed in the following table,
or a combination of one “state…” value plus one “adjust…” value.
Setting multiple values in either group — multiple “state…” values,
for example — has undefined results. Individual values are separated
by a vertical bar (|). For example:
但是我没有正确地阅读OP问题而且他的scrollview没有移动.这需要一个添加到滚动视图的OnGlobalLayoutListener().
final View activityRootView = findViewById(R.id.activityRoot);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
//r will be populated with the coordinates of your view that area still visible.
activityRootView.getWindowVisibleDisplayFrame(r);
int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
... do something here
}
}
});
Here are some awesome way to do it.上面的代码来自@Kachi.