Asa*_*saf 21 xml android android-layout android-fragments android-activity
在我的主要活动中有一个RelativeLayout有2个孩子:
ImageView其用作背景LinearLayout有2个片段容器<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
tools:context="${packageName}.${activityClass}">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:baselineAlignBottom="false"
android:scaleType="fitStart"
android:src="@drawable/bg_image" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="?android:attr/actionBarSize"
android:layout_alignParentBottom="true">
<LinearLayout
android:id="@+id/ContainerA"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical" />
<LinearLayout
android:id="@+id/ContainerB"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background_gray"
android:orientation="vertical" />
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
容器A只显示一个不会改变的片段.
但是,容器B保存的片段会根据用户点击进行更改.
容器B以两种方式改变:
容器B可以容纳的一个片段是一个包含EditTexts和其他视图的表单.
我的问题是当键盘打开时我无法调整活动的大小.
我adjustResize在清单文件中设置,我的主题不是全屏主题(显然这是导致此问题的原因).我也尝试编辑视图,添加ScrollViews但绝对没有任何效果.
我正在用于此活动的主题是带有AppCompat图库中暗动作条的灯光主题.我只编辑了主题以允许叠加操作栏.这不是问题,因为我已经尝试删除这些编辑无济于事.
TL; DR adjustResize/adjustPan不适合我.搜索,尝试了各种解决方案,没有任何效果.我的问题是; 在我的情况下,这是什么原因?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" ...>
<uses-sdk android:minSdkVersion="11" android:targetSdkVersion="19" />
<application ... android:theme="@style/AppTheme">
<activity android:name=".SplashScreenActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:configChanges="keyboardHidden|screenSize" android:label="@string/app_name"
android:screenOrientation="portrait" android:theme="@style/OverlayActionBarTheme"
android:windowSoftInputMode="adjustResize" />
<activity android:name=".SettingsActivity"
android:label="@string/title_activity_settings"
android:parentActivityName=".MainActivity"
android:windowSoftInputMode="adjustResize">
<meta-data android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
更新2:
我创建了一个全新的应用程序,添加了我的表单布局作为主要布局,并测试了问题是否在布局本身.事实证明,就像这个新创建的应用程序一样,它似乎没有调整大小.
如上所述,可以在此处找到布局的链接
更新3:
我设法通过围绕整个布局使其在新应用程序上工作ScrollView.由于某种原因,我无法在原始应用程序中复制相同的效果...仍然试图找出原因.
Man*_*ani 24
当软键盘出现在屏幕上时,应用程序UI的可用空间量会减少.系统决定如何组织应用程序的UI和软键盘之间的可用空间.
ListView,ScrollView则会调整应用程序的窗口大小,前提是所有内容都可见.pan and scan则使用方法,其仅涉及滚动应用程序的窗口以使得当前聚焦的视图可见.由于您的布局不包含任何内容ListView,ScrollView因此排除了重新调整大小.
窗口的根视图是FrameLayout您最初添加的视图LinearLayout.由于LinearLayout不支持滚动,pan and scan因此也排除了方法.因此,在ScrollView中包装布局可以解决滚动问题.
您可以参考Android开发者博客了解更多详情.
更新1:
如本回答所示,OP能够解决问题.问题是发生由于一个片段覆盖动画陆续片段和这些的父母Fragment的是一个LinearLayout.出于叠加目的,您需要使用RelativeLayout或FrameLayout仅使用.
Vai*_*iya 11
要将模式更改为"调整大小",请将以下语句中的"调整大小"更改为"AndroidManifest.xml"中的活动.
Run Code Online (Sandbox Code Playgroud)<activity android:name=".ActivityName" android:windowSoftInputMode="adjustResize">
并且请删除LinearLayout的复杂性(意味着你使用多级LinearLayout)而不是你也可以使用RelativeLayout ..使用这个你可以轻松地设置你想要的布局..尝试它也希望你的问题可能整流
我希望这有帮助.
Ram*_*ash 10
您也可以在Fragment中使用此代码
此代码提供了调整大小视图的帮助
public static class MyDialog extends DialogFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Dialog layout inflater code
// getDialog() need to be called only after onCreateDialog(), which is invoked between onCreate() and onCreateView().
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
// return view code
}
}
Run Code Online (Sandbox Code Playgroud)
在您的清单文件中使用此行来反对您希望结果希望它可以帮助您的活动
android:windowSoftInputMode="adjustPan|stateAlwaysHidden"
Run Code Online (Sandbox Code Playgroud)
喜欢
<activity
android:name="com.android.youractivity"
android:windowSoftInputMode="adjustPan|stateAlwaysHidden" />
Run Code Online (Sandbox Code Playgroud)
原来我的问题是由完全意外的来源引起的。
发生的是,我使用a LinearLayout作为我的两个片段容器的父对象。
然后,在展开的动画中,我抬起底部容器,使其与另一个容器重叠。
我真的不知道为什么,但是既然LinearLayout不应该抱重叠的孩子,改用a RelativeLayout或FrameLayout立即解决这个问题。
由于从我发布的代码中可能看不到这种原因,因此我想对信息的缺乏表示歉意,并将把最详细的答案归为最佳答案。
在BottomSheetFragment / Dailogfragment的onCreateDialog中使用它
KeyboardUtil(getActivity(), view);
Run Code Online (Sandbox Code Playgroud)
要么
供片段使用
new KeyboardUtil(this, findViewById(R.id.fragment_container));
Run Code Online (Sandbox Code Playgroud)
通过使用此Util类
图片来源:Mikepenz
| 归档时间: |
|
| 查看次数: |
27656 次 |
| 最近记录: |