简体   繁体   中英

TextView and Checkbox inside LinearLayout, but Checkbox disappears

I have TextView and CheckBox inside LinearLayout. Checkbox must appear to the right of the TextView. In the Eclipse View, Checkbox appear, but when i launch app in my device checkbox disappears.

This is Eclipse view (Checkbox is the star):

在此处输入图片说明

This is part of my xml file:

    <RelativeLayout 
    android:id="@+id/infoinstalacion_fragment1_relative_imagen_poli"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:layout_weight="100">

<ImageView
    android:id="@+id/infoinstalacion_fragment1_imgfoto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scaleType="fitXY"
    android:src="@drawable/pld_alza" />

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/infoinstalacion_fragment1_imgfoto"
    android:background="@color/transparent">

<TextView
    android:id="@+id/infoinstalacion_fragment1_nombre_encima_de_imagen"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:paddingRight="35dp"
    android:textSize="20dp"
    android:textStyle="bold"
    android:textAllCaps="true"
    android:textColor="@color/white"
    android:lines="2"
    android:text="Esto es un polideportivo" 
    android:gravity="center_vertical"/>

            <CheckBox
    android:id="@+id/infoinstalacion_fragment1_checkbox_favorito"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:focusable="true"
    android:button="@drawable/checkbox_favorito"/>

</LinearLayout>

Does anyone know what the problem is?

Thank.

try assigning weight to linearlayout and it's children like this:

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:orientation="horizontal"
android:layout_alignBottom="@+id/infoinstalacion_fragment1_imgfoto"
android:background="@color/transparent">

<TextView
android:id="@+id/infoinstalacion_fragment1_nombre_encima_de_imagen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:paddingRight="35dp"
android:textSize="20dp"
android:textStyle="bold"
android:textAllCaps="true"
android:textColor="@color/white"
android:lines="2"
android:layout_weight="0.70"
android:text="Esto es un polideportivo" 
android:gravity="center_vertical"/>

        <CheckBox
android:id="@+id/infoinstalacion_fragment1_checkbox_favorito"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:layout_weight="0.30"
android:button="@drawable/checkbox_favorito"/>

Hope it helps !

I think you should try to add this to your LinearLayout:

android:orientation="horizontal"

Although the default orientation value for LinearLayout is horizontal,in some build version of android build tools ,there's some problems if you don't set the value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM