【问题标题】:What's the difference between bringToFront in Android 4 and Android 5?Android 4 和 Android 5 中的 bringToFront 有什么区别?
【发布时间】:2015-11-04 01:07:16
【问题描述】:

我有一个带有 DrawerLayout 和 ScrollView 的布局:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".InformacionTienda">

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="260dp"
    android:layout_height="match_parent"
    android:layout_marginTop="70dp">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingLeft="10dp"
        android:paddingRight="10dp">

        <android.support.v7.widget.CardView
            android:id="@+id/quienesSomosCv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/quienesSomosCabecera"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:background="#010001"
                    android:text="¿Quiénes somos?"
                    android:textColor="#fffcf7"
                    android:textSize="@dimen/tamano_localizacion" />

                <TextView
                    android:id="@+id/quienesSomosTexto"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/quienesSomosCabecera"
                    android:layout_centerHorizontal="true"
                    android:paddingTop="5dp"
                    android:text="test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test " />
            </RelativeLayout>
        </android.support.v7.widget.CardView>


        <android.support.v7.widget.CardView
            android:id="@+id/mapaCv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/localizacionCabecera"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:background="#010001"
                    android:text="Localización"
                    android:textColor="#fffcf7"
                    android:textSize="@dimen/tamano_localizacion" />

                <ImageView
                    android:id="@+id/mapa"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/tamano_mapa"
                    android:layout_below="@+id/localizacionCabecera"
                    android:layout_centerHorizontal="true"
                    android:scaleType="centerCrop"
                    android:src="@drawable/empresa_icon" />

            </RelativeLayout>
        </android.support.v7.widget.CardView>


        <android.support.v7.widget.CardView
            android:id="@+id/contactoCv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/contactoCabecera"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:background="#010001"
                    android:text="Contacto"
                    android:textColor="#fffcf7"
                    android:textSize="@dimen/tamano_localizacion" />

                <TextView
                    android:id="@+id/telefono"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/contactoCabecera"
                    android:paddingTop="5dp"
                    android:text="Telefono: 666 666 666" />

                <ImageButton
                    android:id="@+id/botonLlamar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignEnd="@+id/telefono"
                    android:layout_alignRight="@+id/telefono"
                    android:background="@drawable/ic_launcher" />

                <ImageButton
                    android:id="@+id/botonMail"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignEnd="@+id/telefono"
                    android:layout_alignRight="@+id/telefono"
                    android:layout_below="@+id/botonLlamar"
                    android:background="@drawable/ic_launcher" />

                <TextView
                    android:id="@+id/calle"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/telefono"
                    android:paddingTop="5dp"
                    android:text="Calle: El 742 de Evergreen Terrace" />

                <TextView
                    android:id="@+id/facebook"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/calle"
                    android:autoLink="web"
                    android:paddingTop="5dp"
                    android:text="www.facebook.com" />

                <TextView
                    android:id="@+id/mail"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/facebook"
                    android:autoLink="email"
                    android:paddingTop="5dp"
                    android:text="email@email.com" />

            </RelativeLayout>

        </android.support.v7.widget.CardView>
    </LinearLayout>
</ScrollView>
<!-- Contenido de la actividad -->
<include layout="@layout/content_layout" />
<!-- Navigation Drawer Layout -->
<include layout="@layout/navdrawer_layout" />

</android.support.v4.widget.DrawerLayout>

有人知道为什么它在 Android 4 中是这样的吗? (并且完美地工作): http://snag.gy/DKgk9.jpg

为什么看起来像在 Android 5 中? http://snag.gy/WjVXh.jpg

bringChildToFront 函数也是如此。

【问题讨论】:

  • 你说的是v21和v19吗?
  • 我在真实终端上测试过,Android 5.0.1和Android 4.2.2
  • 其实我在activity中有这个:sv = (ScrollView) findViewById(R.id.scrollView); sv.bringToFront();如果我评论这一行,我可以使用 navDrawer 栏,但是我不能滚动

标签: android navigation-drawer android-scrollview bringtofront


【解决方案1】:

我有办法!

我只需要把一个LinearLayout作为scrollView的父亲:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".InformacionTienda">

<LinearLayout
    android:id="@+id/testlayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="70dp"
    android:paddingTop="70dp">

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingLeft="10dp"
            android:paddingRight="10dp">

            <android.support.v7.widget.CardView
                android:id="@+id/quienesSomosCv"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <TextView
                        android:id="@+id/quienesSomosCabecera"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:background="#010001"
                        android:text="¿Quiénes somos?"
                        android:textColor="#fffcf7"
                        android:textSize="@dimen/tamano_localizacion" />

                    <TextView
                        android:id="@+id/quienesSomosTexto"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/quienesSomosCabecera"
                        android:layout_centerHorizontal="true"
                        android:paddingTop="5dp"
                        android:text="test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test " />
                </RelativeLayout>
            </android.support.v7.widget.CardView>


            <android.support.v7.widget.CardView
                android:id="@+id/mapaCv"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <TextView
                        android:id="@+id/localizacionCabecera"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:background="#010001"
                        android:text="Localización"
                        android:textColor="#fffcf7"
                        android:textSize="@dimen/tamano_localizacion" />

                    <ImageView
                        android:id="@+id/mapa"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/tamano_mapa"
                        android:layout_below="@+id/localizacionCabecera"
                        android:layout_centerHorizontal="true"
                        android:scaleType="centerCrop"
                        android:src="@drawable/empresa_icon" />

                </RelativeLayout>
            </android.support.v7.widget.CardView>


            <android.support.v7.widget.CardView
                android:id="@+id/contactoCv"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <TextView
                        android:id="@+id/contactoCabecera"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:background="#010001"
                        android:text="Contacto"
                        android:textColor="#fffcf7"
                        android:textSize="@dimen/tamano_localizacion" />

                    <TextView
                        android:id="@+id/telefono"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/contactoCabecera"
                        android:paddingTop="5dp"
                        android:text="Telefono: 666 666 666" />

                    <ImageButton
                        android:id="@+id/botonLlamar"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignEnd="@+id/telefono"
                        android:layout_alignRight="@+id/telefono"
                        android:background="@drawable/ic_launcher" />

                    <ImageButton
                        android:id="@+id/botonMail"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignEnd="@+id/telefono"
                        android:layout_alignRight="@+id/telefono"
                        android:layout_below="@+id/botonLlamar"
                        android:background="@drawable/ic_launcher" />

                    <TextView
                        android:id="@+id/calle"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/telefono"
                        android:paddingTop="5dp"
                        android:text="Calle: El 742 de Evergreen Terrace" />

                    <TextView
                        android:id="@+id/facebook"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/calle"
                        android:autoLink="web"
                        android:paddingTop="5dp"
                        android:text="www.facebook.com" />

                    <TextView
                        android:id="@+id/mail"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/facebook"
                        android:autoLink="email"
                        android:paddingTop="5dp"
                        android:text="email@email.com" />

                </RelativeLayout>

            </android.support.v7.widget.CardView>
        </LinearLayout>
    </ScrollView>
</LinearLayout>
<!-- Contenido de la actividad -->
<include layout="@layout/content_layout" />
<!-- Navigation Drawer Layout -->
<include layout="@layout/navdrawer_layout" />

非常感谢!

【讨论】:

    猜你喜欢
    • 2012-10-15
    • 2011-03-10
    • 2023-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-25
    • 2021-05-24
    • 2017-09-13
    相关资源
    最近更新 更多