简体   繁体   中英

Android - ImageView and TextView not appearing

I want to display an ImageView then her TextView details followed by an other ImageView and her TextView details and then a text view and under them an ImageView then her TextView. So i put 2 child LinearLayouts that has orientation set to horizontal and the parent with orientation vertical but the second child LinearLayout is not appearing at all I don't know why. Thank you for helping. This is my activity.xml :

<?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/fondgris"
    android:orientation="horizontal" >

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

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

            <ImageView
                android:id="@+id/imageTypeWorkitem"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingRight="15dp"
                android:paddingTop="10dp"
                android:src="@drawable/bugicon" />

            <TextView
                android:id="@+id/typeWorkitem"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="14sp"
                android:textStyle="bold" />

            <ImageView
                android:id="@+id/imagePriority"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingRight="15dp"
                android:paddingTop="10dp"
                android:src="@drawable/priorityhigh" />

            <TextView
                android:id="@+id/priority"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="14sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/key"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="14sp"
                android:textStyle="bold" />
        </LinearLayout>

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

            <ImageView
                android:id="@+id/imageStatus"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingRight="15dp"
                android:paddingTop="10dp"
                android:src="@drawable/statusopen" />

            <TextView
                android:id="@+id/status"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/priority"
                android:textSize="14sp"
                android:textStyle="bold" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

Your linearLayout1 has the property android:orientation="vertical" but then the very first child ( linearLayout2 ) has android:layout_height="match_parent" , which means the second child ( linearLayout3 ) will have no space since first one will take over full height of the parent.

So you can change both children to have android:layout_height="wrap_content" and maybe add android:layout_weight="1" for both if you want.

The content is larger than the screen and it is hidden. You must use ScrollView .

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewPort="true" >

<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/fondgris"
    android:orientation="horizontal" >
    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical" >

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

            <ImageView
                android:id="@+id/imageTypeWorkitem"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingRight="15dp"
                android:paddingTop="10dp"
                android:src="@drawable/bugicon" />

            <TextView
                android:id="@+id/typeWorkitem"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="14sp"
                android:textStyle="bold" />

            <ImageView
                android:id="@+id/imagePriority"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingRight="15dp"
                android:paddingTop="10dp"
                android:src="@drawable/priorityhigh" />

            <TextView
                android:id="@+id/priority"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="14sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/key"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="14sp"
                android:textStyle="bold" />
        </LinearLayout>

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

            <ImageView
                android:id="@+id/imageStatus"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingRight="15dp"
                android:paddingTop="10dp"
                android:src="@drawable/statusopen" />

            <TextView
                android:id="@+id/status"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/priority"
                android:textSize="14sp"
                android:textStyle="bold" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>
</ScrollView>

不知道我是否理解正确,但是根据您的描述,我将尝试使用相对布局作为父级,并在其中相对于彼此(一个在另一个之上)的线性布局中创建线性布局。

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