【问题标题】:Slim Spinner when i use FILL_PARENT (or MATCH_PARENT) as WIDTH当我使用 FILL_PARENT(或 MATCH_PARENT)作为 WIDTH 时,Slim Spinner
【发布时间】:2016-02-28 15:40:03
【问题描述】:

我在 Spinner 中设置 android:layout_width="fill_parent" 时遇到了一个奇怪的问题:

可点击区域缩小为一条线(红色方块),只有在这条线上按下才能显示 Spinner 的元素:

如果我使用 android:layout_width="wrap_content" 我获得正确的区域:

我想用“fill_parent”做同样的事情

Spinner 的元素已正确显示。唯一的问题是单击 Spinner。 可能的问题是什么?

<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:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#040404"
    android:gravity="center"
    android:paddingTop="2dp"
    android:weightSum="4" >

    <TextView
        android:id="@+id/mpp_movimento_lbl"
        android:background="@drawable/selector_black_btn"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:drawableTop="@drawable/freccia_verde"
        android:gravity="center"
        android:text="@string/Movimento"
        android:textColor="@color/white"
        android:textStyle="bold"
        android:textSize="17sp" />

    <TextView
        android:id="@+id/mpp_eccesso_lbl"
        android:background="@drawable/selector_black_btn"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:drawableTop="@drawable/freccia_rossa"
        android:gravity="center"
        android:text="@string/Eccesso"
        android:textColor="@color/white"
        android:textStyle="bold"
        android:textSize="17sp" />

    <TextView
        android:id="@+id/mpp_fermo_lbl"
        android:background="@drawable/selector_black_btn"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:drawableTop="@drawable/freccia_grigia"
        android:gravity="center"
        android:text="@string/Fermo"
        android:textColor="@color/white"
        android:textStyle="bold"
        android:textSize="17sp" />

    <TextView
        android:id="@+id/mpp_ripristina_lbl"
        android:background="@drawable/selector_black_btn"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:drawableTop="@drawable/ripristina_mappa_40x40"
        android:gravity="center"
        android:text="@string/Ripristina"
        android:textColor="@color/white"
        android:textStyle="bold"
        android:textSize="17sp" />

</LinearLayout>

<TextView
    android:id="@+id/mpp_automezzi_visualizzati_lbl"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/black"
    android:gravity="center"
    android:paddingTop="5dp"
    android:text="@string/AutomezziVisualizzati"
    android:textColor="@color/white"
    android:textSize="17sp" />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/white"
    android:paddingTop="5dp" >

    <FrameLayout
        android:id="@+id/mpp_spinner_frame_fly"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@+id/mpp_cerca_btn" >

        <Spinner
            android:id="@+id/mpp_spinner_spn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:textSize="17sp" />

    </FrameLayout>

    <ImageButton
        android:id="@+id/mpp_cerca_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="5dp"
        android:background="@drawable/selector_white_btn"
        android:contentDescription="@string/DescrizioneCerca"
        android:gravity="center"
        android:onClick="doCerca"
        android:src="@drawable/cerca" />
</RelativeLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="5dp"
    android:background="#040404"
    android:gravity="center" >
</LinearLayout>

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

    <fragment
        android:id="@+id/mpp_mappa_fragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        class="com.google.android.gms.maps.SupportMapFragment" />

</RelativeLayout>

【问题讨论】:

  • 能否请您发布您的布局文件?

标签: android onclick spinner


【解决方案1】:

尝试将 Spinner 的父级高度设置为 match_parent。而且你真的需要这样的布局吗?不需要在FrameLayout中放置spinner,尝试将spinner的权重设置为1并将RelativeLayout替换为LinearLayout

【讨论】:

  • 是的,FrameLayout 没用(我尝试仅使用它来解决问题)。如果我使用宽度 = fill_parent 或 weight = 1 的 LinearLayout 和 Spinner,我看不到右边的 ImageButton
  • 好吧,我建议你将RelativeLayouth替换为LinearLayout,然后将Spinner的权重设置为1,宽度设置为0dp
  • 好的,我尝试删除 FrameLayout 并使用 但问题依然存在
  • 很奇怪,你有没有使用 Android SDK 的 HierarchyViewer 观察到你的视图层次结构(它包含在监控工具中,它可以连接到模拟器或根设备)?微调器这么薄还是因为某些视图覆盖了它?
  • 我无法使用 HV,因为我没有开发人员的设备,并且本指南中建议的项目“ViewServer”jmlinnik.blogspot.it/2012/08/… 给了我一些错误
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-04-14
  • 1970-01-01
  • 2011-08-11
  • 1970-01-01
  • 2012-06-29
  • 2013-04-02
  • 1970-01-01
相关资源
最近更新 更多