添加滚动视图,并突出对线性布局Android版 [英] Add scrollView and highlight on a Linear Layout in Android

查看:179
本文介绍了添加滚动视图,并突出对线性布局Android版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的LinearLayout 有多个线性布局,其中主要的布局之一,有一个的LinearLayout 列表视图的LinearLayout 包含多个的ImageView 的TextView 现在我要添加滚动型在此的LinearLayout 。但是,如果我加入滚动型我的的ListView 得到了隐藏和的onClick 的ImageView的我要强调的是的LinearLayout

我的 XML 是:

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:方向=垂直>    <的LinearLayout
        机器人:ID =@ + ID / mainFilterLayout
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:方向=垂直>        <的LinearLayout
            机器人:layout_width =match_parent
            机器人:layout_height =WRAP_CONTENT
            机器人:方向=横向>
            < ImageView的
                机器人:ID =@ + ID / CompanyLogo的
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_weight =1
                机器人:layout_gravity =左
                机器人:adjustViewBounds =真
                机器人:背景=@的mipmap / ic_launcher/>
            <查看
                机器人:可点击=真
                机器人:layout_gravity =中心
                机器人:layout_width =0dp
                机器人:layout_height =match_parent
                机器人:layout_weight =1/>
            <按钮
                机器人:ID =@ + ID / btnClear
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_gravity =右|中心
                机器人:重力=右|中心
                机器人:文字=清除/>            <按钮
                机器人:ID =@ + ID / btnApply
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_gravity =右|中心
                机器人:重力=右|中心
                机器人:文字=应用/>
        < / LinearLayout中>        <的LinearLayout
            机器人:layout_width =match_parent
            机器人:layout_height =match_parent
            机器人:方向=横向>
// **我想在这个线性布局添加滚动视图**
            <的LinearLayout
                机器人:ID =@ + ID / categoryLayout
                机器人:layout_width =0dp
                机器人:layout_height =match_parent
                机器人:layout_weight =2
                机器人:方向=垂直>                <的LinearLayout
                    机器人:ID =@ + ID / brandLayout
                    机器人:layout_width =match_parent
                    机器人:layout_height =70dp
                    机器人:方向=垂直>
// **这里就imageviwew的点击,我想设置为选择这个线性布局**
                    < ImageView的
                        机器人:ID =@ + ID / mobbrand
                        机器人:layout_width =90dp
                        机器人:layout_height =50dp
                        机器人:背景=@的mipmap / ic_launcher
                        机器人:layout_gravity =中心/>                    <的TextView
                        机器人:ID =@ + ID / txtBrand
                        机器人:layout_width =WRAP_CONTENT
                        机器人:layout_height =WRAP_CONTENT
                        机器人:layout_gravity =中心
                        机器人:比重=中心
                        机器人:文字=品牌/>
                < / LinearLayout中>                <的LinearLayout
                    机器人:ID =@ + ID / colorLayout
                    机器人:layout_width =match_parent
                    机器人:layout_height =70dp
                    机器人:方向=垂直>                    < ImageView的
                        机器人:ID =@ + ID / mobColor
                        机器人:layout_width =90dp
                        机器人:layout_height =50dp
                        机器人:背景=@的mipmap / ic_launcher
                        机器人:layout_gravity =中心/>                    <的TextView
                        机器人:ID =@ + ID / txtColor
                        机器人:layout_width =WRAP_CONTENT
                        机器人:layout_height =WRAP_CONTENT
                        机器人:layout_gravity =中心
                        机器人:比重=中心
                        机器人:文字=彩色/>
                < / LinearLayout中>                <的LinearLayout
                    机器人:ID =@ + ID / sizeLayout
                    机器人:layout_width =match_parent
                    机器人:layout_height =70dp
                    机器人:方向=垂直>                    < ImageView的
                        机器人:ID =@ + ID / mobSize
                        机器人:layout_width =90dp
                        机器人:layout_height =50dp
                        机器人:背景=@的mipmap / ic_launcher
                        机器人:layout_gravity =中心/>                    <的TextView
                        机器人:ID =@ + ID / txtSize
                        机器人:layout_width =WRAP_CONTENT
                        机器人:layout_height =WRAP_CONTENT
                        机器人:layout_gravity =中心
                        机器人:比重=中心
                        机器人:文字=大小/>
                < / LinearLayout中>                <的LinearLayout
                    机器人:ID =@ + ID / offerLayout
                    机器人:layout_width =match_parent
                    机器人:layout_height =70dp
                    机器人:方向=垂直>                    < ImageView的
                        机器人:ID =@ + ID / mobOffers
                        机器人:layout_width =90dp
                        机器人:layout_height =50dp
                        机器人:layout_gravity =中心
                        机器人:背景=@的mipmap / ic_launcher/>                    <的TextView
                        机器人:ID =@ + ID / txtPrice
                        机器人:layout_width =WRAP_CONTENT
                        机器人:layout_height =WRAP_CONTENT
                        机器人:layout_gravity =中心
                        机器人:比重=中心
                        机器人:文字=价格/>
                < / LinearLayout中>
                <的LinearLayout
                    机器人:ID =@ + ID / othersLayout
                    机器人:layout_width =match_parent
                    机器人:layout_height =70dp
                    机器人:方向=垂直>                    < ImageView的
                        机器人:ID =@ + ID / mobother
                        机器人:layout_width =90dp
                        机器人:layout_height =50dp
                        机器人:layout_gravity =中心
                        机器人:背景=@的mipmap / ic_launcher/>                    <的TextView
                        机器人:ID =@ + ID / txtOther
                        机器人:layout_width =WRAP_CONTENT
                        机器人:layout_height =WRAP_CONTENT
                        机器人:layout_gravity =中心
                        机器人:比重=中心
                        机器人:文字=其它/>
                < / LinearLayout中>
            < / LinearLayout中>            < ListView控件
                机器人:ID =@ + ID /子
                机器人:layout_width =0dp
                机器人:layout_height =match_parent
                机器人:layout_weight =5
                机器人:cacheColorHint =@机器人:彩色/透明
                机器人:分=#FFF
                机器人:dividerHeight =1DP
                机器人:fadingEdge =无>
            < /&的ListView GT;
        < / LinearLayout中>
    < / LinearLayout中>
< / LinearLayout中>


解决方案

我希望这会为ü工作:

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:方向=垂直>    <的LinearLayout
        机器人:ID =@ + ID / mainFilterLayout
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:方向=垂直>        <的LinearLayout
            机器人:layout_width =match_parent
            机器人:layout_height =WRAP_CONTENT
            机器人:方向=横向>
            < ImageView的
                机器人:ID =@ + ID / CompanyLogo的
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_weight =1
                机器人:layout_gravity =左
                机器人:adjustViewBounds =真
                机器人:背景=@的mipmap / ic_launcher/>
            <查看
                机器人:可点击=真
                机器人:layout_gravity =中心
                机器人:layout_width =0dp
                机器人:layout_height =match_parent
                机器人:layout_weight =1/>
            <按钮
                机器人:ID =@ + ID / btnClear
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_gravity =右|中心
                机器人:重力=右|中心
                机器人:文字=清除/>            <按钮
                机器人:ID =@ + ID / btnApply
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_gravity =右|中心
                机器人:重力=右|中心
                机器人:文字=应用/>
        < / LinearLayout中>        <的LinearLayout
            机器人:layout_width =match_parent
            机器人:layout_height =match_parent
            机器人:方向=横向>
            <滚动型
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT>
                <的LinearLayout
                    机器人:layout_width =FILL_PARENT
                    机器人:layout_height =WRAP_CONTENT
                    机器人:layout_weight =2
                    机器人:方向=垂直>                    <的LinearLayout
                        机器人:ID =@ + ID / brandLayout
                        机器人:layout_width =match_parent
                        机器人:layout_height =70dp
                        机器人:方向=垂直>                        < ImageView的
                            机器人:ID =@ + ID / mobbrand
                            机器人:layout_width =90dp
                            机器人:layout_height =50dp
                            机器人:背景=@的mipmap / ic_launcher
                            机器人:layout_gravity =中心/>                        <的TextView
                            机器人:ID =@ + ID / txtBrand
                            机器人:layout_width =WRAP_CONTENT
                            机器人:layout_height =WRAP_CONTENT
                            机器人:layout_gravity =中心
                            机器人:比重=中心
                            机器人:文字=品牌/>
                    < / LinearLayout中>                    <的LinearLayout
                        机器人:ID =@ + ID / colorLayout
                        机器人:layout_width =match_parent
                        机器人:layout_height =70dp
                        机器人:方向=垂直>                        < ImageView的
                            机器人:ID =@ + ID / mobColor
                            机器人:layout_width =90dp
                            机器人:layout_height =50dp
                            机器人:背景=@的mipmap / ic_launcher
                            机器人:layout_gravity =中心/>                        <的TextView
                            机器人:ID =@ + ID / txtColor
                            机器人:layout_width =WRAP_CONTENT
                            机器人:layout_height =WRAP_CONTENT
                            机器人:layout_gravity =中心
                            机器人:比重=中心
                            机器人:文字=彩色/>
                    < / LinearLayout中>                    <的LinearLayout
                        机器人:ID =@ + ID / sizeLayout
                        机器人:layout_width =match_parent
                        机器人:layout_height =70dp
                        机器人:方向=垂直>                        < ImageView的
                            机器人:ID =@ + ID / mobSize
                            机器人:layout_width =90dp
                            机器人:layout_height =50dp
                            机器人:背景=@的mipmap / ic_launcher
                            机器人:layout_gravity =中心/>                        <的TextView
                            机器人:ID =@ + ID / txtSize
                            机器人:layout_width =WRAP_CONTENT
                            机器人:layout_height =WRAP_CONTENT
                            机器人:layout_gravity =中心
                            机器人:比重=中心
                            机器人:文字=大小/>
                    < / LinearLayout中>                    <的LinearLayout
                        机器人:ID =@ + ID / offerLayout
                        机器人:layout_width =match_parent
                        机器人:layout_height =70dp
                        机器人:方向=垂直>                        < ImageView的
                            机器人:ID =@ + ID / mobOffers
                            机器人:layout_width =90dp
                            机器人:layout_height =50dp
                            机器人:layout_gravity =中心
                            机器人:背景=@的mipmap / ic_launcher/>                        <的TextView
                            机器人:ID =@ + ID / txtPrice
                            机器人:layout_width =WRAP_CONTENT
                            机器人:layout_height =WRAP_CONTENT
                            机器人:layout_gravity =中心
                            机器人:比重=中心
                            机器人:文字=价格/>
                    < / LinearLayout中>
                    <的LinearLayout
                        机器人:ID =@ + ID / othersLayout
                        机器人:layout_width =match_parent
                        机器人:layout_height =70dp
                        机器人:方向=垂直>                        < ImageView的
                            机器人:ID =@ + ID / mobother
                            机器人:layout_width =90dp
                            机器人:layout_height =50dp
                            机器人:layout_gravity =中心
                            机器人:背景=@的mipmap / ic_launcher/>                        <的TextView
                            机器人:ID =@ + ID / txtOther
                            机器人:layout_width =WRAP_CONTENT
                            机器人:layout_height =WRAP_CONTENT
                            机器人:layout_gravity =中心
                            机器人:比重=中心
                            机器人:文字=其它/>
                    < / LinearLayout中>
                < / LinearLayout中>
            < /滚动型>
            < ListView控件
                机器人:ID =@ + ID /子
                机器人:layout_width =0dp
                机器人:layout_height =match_parent
                机器人:layout_weight =5
                机器人:cacheColorHint =@机器人:彩色/透明
                机器人:分=#FFF
                机器人:dividerHeight =1DP
                机器人:fadingEdge =无>
            < /&的ListView GT;
        < / LinearLayout中>
    < / LinearLayout中>
< / LinearLayout中>

I have Linearlayout that have have multiple linear layouts in which one of the main layout have a LinearLayout and Listview. LinearLayout contains multiple ImageView and TextView now I want to add ScrollView on this LinearLayout. But if I am adding the ScrollView my ListView got hidden and onClick of the ImageView I want to highlight that LinearLayout.

My XML is :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:id ="@+id/mainFilterLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <ImageView
                android:id="@+id/companyLogo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight=".1"
                android:layout_gravity="left"
                android:adjustViewBounds="true"
                android:background="@mipmap/ic_launcher" />
            <View
                android:clickable="true"
                android:layout_gravity="center"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1" />
            <Button
                android:id="@+id/btnClear"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right|center"
                android:gravity="right|center"
                android:text="Clear" />

            <Button
                android:id="@+id/btnApply"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right|center"
                android:gravity="right|center"
                android:text="Apply" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">
//**I want to add scroll view on this linear layout**
            <LinearLayout
                android:id="@+id/categoryLayout"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="2"
                android:orientation="vertical">

                <LinearLayout
                    android:id="@+id/brandLayout"
                    android:layout_width="match_parent"
                    android:layout_height="70dp"
                    android:orientation="vertical">
//**Here on click of imageviwew i want set as selected for this linear layout**
                    <ImageView
                        android:id="@+id/mobbrand"
                        android:layout_width="90dp"
                        android:layout_height="50dp"
                        android:background="@mipmap/ic_launcher"
                        android:layout_gravity="center" />

                    <TextView
                        android:id="@+id/txtBrand"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:gravity="center"
                        android:text="Brand" />
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/colorLayout"
                    android:layout_width="match_parent"
                    android:layout_height="70dp"
                    android:orientation="vertical">

                    <ImageView
                        android:id="@+id/mobColor"
                        android:layout_width="90dp"
                        android:layout_height="50dp"
                        android:background="@mipmap/ic_launcher"
                        android:layout_gravity="center" />

                    <TextView
                        android:id="@+id/txtColor"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:gravity="center"
                        android:text="COLOUR" />
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/sizeLayout"
                    android:layout_width="match_parent"
                    android:layout_height="70dp"
                    android:orientation="vertical">

                    <ImageView
                        android:id="@+id/mobSize"
                        android:layout_width="90dp"
                        android:layout_height="50dp"
                        android:background="@mipmap/ic_launcher"
                        android:layout_gravity="center" />

                    <TextView
                        android:id="@+id/txtSize"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:gravity="center"
                        android:text="Size" />
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/offerLayout"
                    android:layout_width="match_parent"
                    android:layout_height="70dp"
                    android:orientation="vertical">

                    <ImageView
                        android:id="@+id/mobOffers"
                        android:layout_width="90dp"
                        android:layout_height="50dp"
                        android:layout_gravity="center"
                        android:background="@mipmap/ic_launcher" />

                    <TextView
                        android:id="@+id/txtPrice"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:gravity="center"
                        android:text="Price" />
                </LinearLayout>


                <LinearLayout
                    android:id="@+id/othersLayout"
                    android:layout_width="match_parent"
                    android:layout_height="70dp"
                    android:orientation="vertical">

                    <ImageView
                        android:id="@+id/mobother"
                        android:layout_width="90dp"
                        android:layout_height="50dp"
                        android:layout_gravity="center"
                        android:background="@mipmap/ic_launcher" />

                    <TextView
                        android:id="@+id/txtOther"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:gravity="center"
                        android:text="OTHER" />
                </LinearLayout>
            </LinearLayout>

            <ListView
                android:id="@+id/subCategory"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="5"
                android:cacheColorHint="@android:color/transparent"
                android:divider="#fff"
                android:dividerHeight="1dp"
                android:fadingEdge="none">
            </ListView>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

解决方案

I hope this will work for u :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:id ="@+id/mainFilterLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <ImageView
                android:id="@+id/companyLogo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight=".1"
                android:layout_gravity="left"
                android:adjustViewBounds="true"
                android:background="@mipmap/ic_launcher" />
            <View
                android:clickable="true"
                android:layout_gravity="center"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1" />
            <Button
                android:id="@+id/btnClear"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right|center"
                android:gravity="right|center"
                android:text="Clear" />

            <Button
                android:id="@+id/btnApply"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right|center"
                android:gravity="right|center"
                android:text="Apply" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">
            <ScrollView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="2"
                    android:orientation="vertical">

                    <LinearLayout
                        android:id="@+id/brandLayout"
                        android:layout_width="match_parent"
                        android:layout_height="70dp"
                        android:orientation="vertical">

                        <ImageView
                            android:id="@+id/mobbrand"
                            android:layout_width="90dp"
                            android:layout_height="50dp"
                            android:background="@mipmap/ic_launcher"
                            android:layout_gravity="center" />

                        <TextView
                            android:id="@+id/txtBrand"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:gravity="center"
                            android:text="Brand" />
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/colorLayout"
                        android:layout_width="match_parent"
                        android:layout_height="70dp"
                        android:orientation="vertical">

                        <ImageView
                            android:id="@+id/mobColor"
                            android:layout_width="90dp"
                            android:layout_height="50dp"
                            android:background="@mipmap/ic_launcher"
                            android:layout_gravity="center" />

                        <TextView
                            android:id="@+id/txtColor"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:gravity="center"
                            android:text="COLOUR" />
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/sizeLayout"
                        android:layout_width="match_parent"
                        android:layout_height="70dp"
                        android:orientation="vertical">

                        <ImageView
                            android:id="@+id/mobSize"
                            android:layout_width="90dp"
                            android:layout_height="50dp"
                            android:background="@mipmap/ic_launcher"
                            android:layout_gravity="center" />

                        <TextView
                            android:id="@+id/txtSize"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:gravity="center"
                            android:text="Size" />
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/offerLayout"
                        android:layout_width="match_parent"
                        android:layout_height="70dp"
                        android:orientation="vertical">

                        <ImageView
                            android:id="@+id/mobOffers"
                            android:layout_width="90dp"
                            android:layout_height="50dp"
                            android:layout_gravity="center"
                            android:background="@mipmap/ic_launcher" />

                        <TextView
                            android:id="@+id/txtPrice"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:gravity="center"
                            android:text="Price" />
                    </LinearLayout>


                    <LinearLayout
                        android:id="@+id/othersLayout"
                        android:layout_width="match_parent"
                        android:layout_height="70dp"
                        android:orientation="vertical">

                        <ImageView
                            android:id="@+id/mobother"
                            android:layout_width="90dp"
                            android:layout_height="50dp"
                            android:layout_gravity="center"
                            android:background="@mipmap/ic_launcher" />

                        <TextView
                            android:id="@+id/txtOther"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:gravity="center"
                            android:text="OTHER" />
                    </LinearLayout>
                </LinearLayout>
            </ScrollView>
            <ListView
                android:id="@+id/subCategory"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="5"
                android:cacheColorHint="@android:color/transparent"
                android:divider="#fff"
                android:dividerHeight="1dp"
                android:fadingEdge="none">
            </ListView>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

这篇关于添加滚动视图,并突出对线性布局Android版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆