【发布时间】:2014-10-07 19:46:01
【问题描述】:
在我的主要活动中,有一个 RelativeLayout 有 2 个孩子:
- 作为背景的
ImageView - 具有 2 个片段容器的
LinearLayout
activity_main.xml
<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>
容器 A 只显示一个不会改变的片段。
但是,容器 B 包含一个片段,该片段会根据用户点击而发生变化。
容器 B 有两种变化:
- 它可以扩展(从大约 70% 的高度到全高)。
- 它会改变片段。
Container B 可以容纳的片段之一是一个表单,其中包含EditTexts 和其他视图。
我的问题是当键盘打开时我无法让活动调整大小。
我在清单文件中设置了adjustResize,我的主题不是全屏主题(这显然是导致此问题的原因)。我还尝试编辑视图,添加 ScrollViews 但绝对没有任何效果。
我用于此活动的主题是来自AppCompat 库的带有深色操作栏的浅色主题。我只编辑了主题以允许覆盖操作栏。这不是问题,因为我已经尝试删除这些编辑但无济于事。
Here's a link to the form layout
TL;DR adjustResize / adjustPan 不适合我。搜索,尝试了各种解决方案,没有任何效果。我的问题是;我的情况是什么原因造成的?
更新:AndroidManifest.xml
<?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>
更新 2:
我创建了一个全新的应用程序,添加了我的表单布局作为主布局,并测试了问题是否出在布局本身。事实证明,即使在这个新创建的应用程序上,它似乎也没有调整大小。
如上所述,可以找到布局的链接Here
更新 3:
通过用ScrollView 包围整个布局,我设法使它在新应用程序上工作。由于某种原因,我无法在原始应用中复制相同的效果......仍在试图找出原因。
【问题讨论】:
-
你能发一张图片是什么样子的吗
-
@xTCx,您是否尝试过 scrollviews 到 主要活动 和 片段 B 的 XML???
-
请去除 LinearLayout 的复杂性(意味着您使用的是多层 LinearLayout )而不是您也可以使用 RelativeLayout
标签: android xml android-layout android-activity android-fragments