Question

I have the following layout designed to do the following. To the left an red circle with text centralised on top of it. To the right of this I have a text view but it is not appearing.

Underneath there will be other text views, but I have removed these to try and isolate the problem, but it made no difference. Any ideas what I need to change to get the TextView to appear?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/redpink" >

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

    <RelativeLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
        <ImageView
            android:id="@+id/imgCircle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_marginTop="8dp"
            android:src="@drawable/redCircle" />
        <TextView
            android:id="@+id/txtYouScored"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/imgCircle"
            android:layout_alignTop="@+id/imgCircle"
            android:layout_alignRight="@+id/imgCircle"
            android:layout_alignBottom="@+id/imgCircle"
            android:layout_margin="1dp"
            android:gravity="center"
            android:textSize="26dp"
            android:text="You Scored"
            android:textColor="@color/redpink" />
    </RelativeLayout>

    <TextView
    android:id="@+id/txtImpact"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Impact text"
        android:textSize="28dp"
        android:textColor="@color/white" />

</LinearLayout>

 </LinearLayout>

Was it helpful?

Solution

Change the inner LinearLayout orientation to

android:orientation="vertical"

In a horizontal linear layout, the TextView is based to the right of the RelativeLayout already taking up all width.

Alternatively, just remove the inner LinearLayout. It does not seem to serve a purpose here as there's already a vertical top-level LinearLayout.

OTHER TIPS

You shouldn't use android:layout_width="fill_parent" on first child of a horizontal LinearLayout.

Try to add weight

try following hope this will help you

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"

android:background="@color/redpink" >

<RelativeLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:layout_weight="1">
    <ImageView
        android:id="@+id/imgCircle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:src="@drawable/redCircle" />
    <TextView
        android:id="@+id/txtYouScored"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/imgCircle"
        android:layout_alignTop="@+id/imgCircle"
        android:layout_alignRight="@+id/imgCircle"
        android:layout_alignBottom="@+id/imgCircle"
        android:layout_margin="1dp"
        android:gravity="center"
        android:textSize="26dp"
        android:text="You Scored"
        android:textColor="@color/redpink" />
</RelativeLayout>

<TextView
android:id="@+id/txtImpact"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Impact text"
    android:textSize="28dp"
    android:textColor="@color/white" />

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top