【问题标题】:Not showing LinearLayout style in a ListView's header未在 ListView 的标题中显示 LinearLayout 样式
【发布时间】:2013-03-12 00:55:04
【问题描述】:

我有一个带有标题的ListView。在此标头中,LinearLayout 具有预定义的样式。问题是这个布局没有显示那种风格。

标头代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    style="?blueHardBackground"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dip"
    android:layout_marginRight="5dip"
    android:layout_marginTop="2dp"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:orientation="horizontal" >

        <Spinner
            android:id="@+id/spinnerCiudad"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawSelectorOnTop="true" />

        <Spinner
            android:id="@+id/spinnerCategoria"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawSelectorOnTop="true" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal" >

        <EditText
            android:id="@+id/textNombreElemento"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10"
            android:textSize="6pt"
            android:typeface="serif" >

            <requestFocus />
        </EditText>

        <ImageView
            android:id="@+id/botonFiltrar"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:contentDescription="Mostrar"
            android:src="@drawable/buscar_n" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/capaNumResultados"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/textNumResultados"
            style="?textRegular"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="" />
    </LinearLayout>

</LinearLayout>

它应该以蓝色圆角显示在中心,但它显示为透明且没有样式,位于左侧。

【问题讨论】:

    标签: android android-layout header android-listview styles


    【解决方案1】:

    我相信你想要

    style="?style/blueHardBackground">
    

    在你的LinearLayout 中而不是

    style="?blueHardBackground">
    

    您在“?”之后缺少style告诉 xml 在哪里查找名称 blueHardBackground

    This Link in the Docs 解释访问resources

    【讨论】:

    • 我更新了我的答案以向您展示差异。希望这会有所帮助
    • 感谢您的努力。如果我把你说的话:错误:错误:找不到与给定名称匹配的资源(在'style',值为'?style/blueHardBackground')。一定有什么问题。问题是我无法居中或更改任何参数。
    • 您显然没有将blueHardBackground 添加为resource。另外,只是一点建议,您的layout 可能会更容易和更有效作为RelativeLayout,因为您有多个LinearLayouts,只有一个孩子
    • 是的,我有,事实上,还有其他图层他们得到了样式。我试着改成亲戚……但没有用
    • 只是更改为RelativeLayout 不会解决问题。我打算这样做并删除不需要的LinearLayouts。这将需要更多时间,但从长远来看可能会使您受益。您希望根布局居中吗?尝试发布您想要的结果的图片,它会更容易提供帮助,但我仍然建议使用 RelativeLayout 重新制作它
    猜你喜欢
    • 2010-11-17
    • 2012-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-03
    • 2010-12-28
    相关资源
    最近更新 更多