当键盘可见时,EditText下面的按钮不可见
我有一个窗体和下面的按钮,当键盘可见时应该可见,但我无法管理该状态。 我知道我的XML文件是在活动中我已经有点凌乱:)当键盘可见时,EditText下面的按钮不可见
-
在清单:
机器人:标签= “@字符串/ APP_NAME” 机器人:windowSoftInputMode = “adjustResize” 机器人:screenOrientation =“portrait” android:configChanges =“orientation”
-
xml文件看起来像这样。我有问题粘贴XML文件这里,所以我很抱歉关于乱
com.myapp.components.NonInvasiveScrollView
的android:layout_width = “match_parent” 机器人:layout_height = “WRAP_CONTENT” 机器人:背景= “#FFFFFF”
机器人:fillViewport = “真”的LinearLayout 的android:layout_width = “match_parent” 机器人:layout_height = “WRAP_CONTENT” 机器人:滚动条= “无” 机器人:fadingEdgeLength = “0dp”
的android:paddingBottom来= “10dp”
机器人:方向= “垂直”><HorizontalScrollView android:id="@+id/hor_scrollview" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:fadingEdgeLength="0dp" android:scrollbars="none" android:overScrollMode="never" android:paddingTop="15dp" > <ImageView android:id="@+id/vizual" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/vizual" /> </HorizontalScrollView> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:layout_marginBottom="5dp" > <RadioGroup android:id="@+id/add_tabs" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/add_fragment_margin" android:layout_marginRight="@dimen/add_fragment_margin" android:orientation="horizontal" android:weightSum="2" > <com.funtasty.appool.components.SegmentedControlButton android:id="@+id/mam_napad" android:layout_width="0dp" android:layout_weight="1" android:checked="true" android:text="Mám nápad na aplikaci" android:singleLine="true" android:textSize="@dimen/smallText" /> <com.myapp.components.SegmentedControlButton android:id="@+id/umim_tvorit" android:layout_width="0dp" android:layout_weight="1" android:checked="false" android:singleLine="true" android:text="Umím tvořit aplikace" android:textSize="@dimen/smallText" /> </RadioGroup> <ViewFlipper android:id="@+id/viewFlipper" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/add_tabs" android:layout_marginLeft="@dimen/add_fragment_margin" android:layout_marginRight="@dimen/add_fragment_margin" android:layout_marginTop="5dp" > <LinearLayout android:id="@+id/add_mam_napad" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <TableRow android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/rowMarginTop" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|left" android:focusable="true" android:src="@drawable/ico_name" /> <EditText android:id="@+id/name" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Jméno a příjmení" android:singleLine="true" android:inputType="text" android:paddingBottom="5dp" android:paddingLeft="10dp" android:layout_marginLeft="2dp" android:layout_marginRight="2dp" android:background="@drawable/edittext" android:focusable="true" android:textSize="@dimen/bigText" android:textColor="@color/gray" android:maxLines="1" /> </TableRow> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/rowMarginTop" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="2dp" android:src="@drawable/ico_mail" /> <EditText android:id="@+id/email" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0" android:hint="E-mail" android:inputType="textEmailAddress" android:background="@drawable/edittext" android:paddingBottom="5dp" android:paddingLeft="10dp" android:layout_marginLeft="2dp" android:layout_marginRight="2dp" android:textColor="@color/gray" android:textSize="@dimen/bigText" android:focusable="true" android:maxLines="1" /> </TableRow> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/rowMarginTop" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="2dp" android:src="@drawable/ico_bulb" /> <EditText android:id="@+id/message" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0" android:background="@drawable/edittext" android:paddingLeft="10dp" android:layout_marginLeft="2dp" android:layout_marginRight="2dp" android:gravity="center_vertical" android:textSize="@dimen/bigText" android:textColor="@color/gray" android:inputType="textMultiLine|textImeMultiLine" android:maxLines="10" android:focusable="true" android:imeOptions="actionDone" android:hint="Popiš svůj nápad" /> </TableRow> </LinearLayout> <LinearLayout android:id="@+id/add_umim_tvorit" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <TableRow android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/rowMarginTop" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|left" android:src="@drawable/ico_name" /> <EditText android:id="@+id/name_umim_tvorit" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0" android:hint="Jméno a příjmení" android:singleLine="true" android:textIsSelectable="true" android:inputType="text" android:paddingBottom="5dp" android:background="@drawable/edittext" android:paddingLeft="10dp" android:focusable="true" android:layout_marginLeft="2dp" android:layout_marginRight="2dp" android:textColor="@color/gray" android:textSize="@dimen/bigText" android:maxLines="1" /> </TableRow> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/rowMarginTop" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="2dp" android:layout_gravity="center_vertical" android:src="@drawable/ico_mail" /> <EditText android:id="@+id/email_umim_tvorit" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0" android:hint="E-mail" android:inputType="textEmailAddress" android:paddingBottom="5dp" android:background="@drawable/edittext" android:paddingLeft="10dp" android:layout_marginLeft="2dp" android:layout_marginRight="2dp" android:textColor="@color/gray" android:textSize="@dimen/bigText" android:focusable="true" android:maxLines="1" /> </TableRow> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/rowMarginTop" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="2dp" android:layout_gravity="center_vertical" android:src="@drawable/ico_bulb" /> <EditText android:id="@+id/message_umim_tvorit" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0" android:background="@drawable/edittext" android:paddingLeft="10dp" android:layout_marginLeft="2dp" android:layout_marginRight="2dp" android:textSize="@dimen/bigText" android:textColor="@color/gray" android:focusable="true" android:inputType="textMultiLine" android:hint="Napiš něco o sobě" /> </TableRow> </LinearLayout> </ViewFlipper> <Button android:id="@+id/button_odeslat" android:layout_width="match_parent" android:layout_height="48dp" android:layout_below="@id/viewFlipper" android:layout_centerHorizontal="true" android:gravity="center" android:layout_marginLeft="@dimen/add_fragment_margin" android:layout_marginRight="@dimen/add_fragment_margin" android:background="@drawable/bg" android:text="Odeslat" android:textColor="@drawable/button_color" android:focusable="true" android:focusableInTouchMode="true" android:enabled="false" android:layout_marginTop="10dp" android:textStyle="bold" /> </RelativeLayout>
我不知道为什么在softInputMode不起作用:/ I只需要使用键盘上方的edittext即可看到该按钮。 谢谢
布尔值checkKeyboard = false;
final android.view.ViewGroup.LayoutParams cur_params = linearScroll.getLayoutParams(); //current layout params
final View activityRootView = findViewById(R.id.activity_image_layout);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
activityRootView.getWindowVisibleDisplayFrame(r);
int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
int margin = activityRootView.getRootView().getHeight()-heightDiff; // screen height without keyboard layout
if (heightDiff > 100) {
if(!checkKeyboard){
// set new layout params ...new LayoutParams(LayoutParams.FILL_PARENT, margin);
checkKeyboard = true;
}
}
else{
// set first layout params cur_params
layout.setLayoutParams(cur_params);
checkKeyboard = false;
}
}
});
,这个activityRootView应该在我的情况下是什么? – vandus
将您的整个布局包装在一个而不是仅使用一个图像。当按钮在键盘后面不可见时,这将确保您可以滚动。
将上面的按钮放在编辑文本中,它会像其他人一样可见 – Charlie
或其右侧。 – Warpzit
那是反对UX设计的,因为首先你填写表格,然后请你点击一个按钮 – vandus