简体   繁体   中英

Where's my ImageViews?

I've got a horizontal LinearLayout (inside of another LinearLayout ) containing a few ImageView s. For some reason I'm just just not seeing them when I run the app.

Here's my layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:background="@drawable/background">
    <TextView android:layout_height="wrap_content"
        android:layout_width="wrap_content" android:textSize="20dp"
        android:text="A bunch of text"
        android:textColor="#000000" android:layout_gravity="center_horizontal"
        android:padding="10dp" android:background="#0000FF"/>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="wrap_content" android:layout_width="fill_parent"
        android:orientation="horizontal">

        <ImageView android:layout_width="wrap_content"
        android:layout_height="75dp"
             android:src="@drawable/image1"
            android:scaleType="centerCrop" android:background="#0000FF"/>
        <ImageView android:layout_width="wrap_content" android:layout_height="75dp"
            android:layout_weight="1" android:src="@drawable/image2"
            android:scaleType="centerCrop" />
        <ImageView android:layout_width="wrap_content" android:layout_height="75dp"
            android:layout_weight="1" android:src="@drawable/image3"
            android:scaleType="centerCrop" />
    </LinearLayout>
</LinearLayout>

I take it that you can see the TextView then? LinearLayout s are horizontal by default. This might be happening because Android is trying to draw the ImageView s to the right of the TextView when I'm guessing you want them below it. Try adding android:orientation="vertical" to the outer LinearLayout and removing android:orientation="horizontal" from the inner LinearLayout (well, you don't need to remove it).

try to change the android:orientation of your LinearLayout to vertical and it will fixe the problem, because the orientation horizontal, it pisses the imageviews out of the screen

Not sure how you want to layout your view, your code looks okay to me, at least those imageviews should show up. Are you sure your image sources ( image1, image2.. ) are not just some plain colors that are same as background color?

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