Android系统 联系人APP,新建联系人时进行横屏切换,左侧头像区域底部显示不全Bug修复

1.问题场景:

新建联系人时进行横屏切换,左侧头像区域底部显示不全,如下图所示:

 

2.布局分析:

(1)land/contact_editor_fragment.xml源文件:

<com.android.contacts.editor.RawContactEditorView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/raw_contacts_editor_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/background_primary"
        android:orientation="horizontal"
        android:visibility="invisible">

    <include layout="@layout/photo_editor_view" />

    <!-- Dummy view so the first input field is not initially focused. b/21644158 -->
    <View
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:focusable="true"
            android:focusableInTouchMode="true"/>

    <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fadingEdge="none"
            android:fillViewport="true">

        <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

            <include layout="@layout/editor_account_header" />

            <include layout="@layout/contact_editor_fields" />

        </LinearLayout>

    </ScrollView>

</com.android.contacts.editor.RawContactEditorView>

其中,photo_editor_view.xml布局如下:

<com.android.contacts.editor.PhotoEditorView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/photo_editor"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal">

    <com.android.contacts.widget.QuickContactImageView
            android:id="@+id/photo"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"/>

    <View
            android:id="@+id/photo_icon_overlay"
            android:layout_height="56dp"
            android:layout_width="match_parent"
            android:layout_alignParentBottom="true" />

    <ImageView
            android:id="@+id/photo_icon"
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentEnd="true"
            android:layout_marginBottom="22dp"
            android:layout_marginEnd="16dp"
            android:background="?android:attr/selectableItemBackground"
            android:tint="@android:color/white"
            android:src="@drawable/quantum_ic_camera_alt_vd_theme_24" />

    <View
            android:id="@+id/photo_touch_intercept_overlay"
            android:focusable="true"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/item_background_material_dark"
            android:contentDescription="@string/editor_change_photo_content_description" />

</com.android.contacts.editor.PhotoEditorView>

 

(2)分析:

这是一个呈左右方向分布的布局,左边为头像部分是一个继承自相对布局的自定义view,右边为ScrollView展示个人信息列表,乍一看并没有啥问题。

3.代码分析:

首先,我的第一个想法是,将左边的view用scrollview包裹,然后也使用android:fillViewport="true"属性使scrollview内容充满屏幕;重新编译后,安装到平板上并没有达到理想的效果,左边部分变得可以滚动,并且头像被拉长,只有上下拖动才能完整显示。

然后,我发现,在竖屏时如果没有弹出软键盘,在翻转到横屏时就不会出现头像显示不全的问题。因此,我在onConfigurationChanged 方法中隐藏了键盘,可惜还是徒劳。

最后,我研究了scrollview和activity的 android:windowSoftInputMode属性,发现软件盘弹起时会占用activity的主窗口空间,影响与用户的交互,网上有些博客建议在最外层包裹ScrollView,我试了之后没有起到作用,考虑到ScrollView也是继承自FrameLayout,因此我使用FrameLayout对左边的布局做了一层包装,最后测试Ok,根本原因还有待继续深究,欢迎大家一起探讨。  

 

 

4.问题解决:

针对land/contact_editor_fragment.xml源文件左边布局,外面包裹了一层FrameLayout,具体如下所示:

<com.android.contacts.editor.RawContactEditorView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/raw_contacts_editor_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/background_primary"
        android:orientation="horizontal"
        android:visibility="invisible">
    <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent">

    	<include layout="@layout/photo_editor_view" />

    </FrameLayout>

    <!-- Dummy view so the first input field is not initially focused. b/21644158 -->
    <!--<View
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:focusable="true"
            android:focusableInTouchMode="true"/>-->

    <ScrollView

            android:fillViewport="true"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

            <include layout="@layout/editor_account_header" />

            <include layout="@layout/contact_editor_fields" />

        </LinearLayout>

    </ScrollView>

</com.android.contacts.editor.RawContactEditorView>

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值