tags:

views:

167

answers:

1
+1  Q: 

LinearLayout usage

What I just want to do it to put some texts in the screen, together with a border that I'm doing(this border will be in the entire screen.)

The problem is that the LinearLayout is adding some texts to outside of the screen, and this I cannot understand why. Why the LinearLayout cannot just keep the elements in the screen size, even if will be very small sizes.

Take a look:

<?xml version="1.0" encoding="utf-8"?>

<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/White">

    <ImageView android:layout_height="wrap_content"
        android:minHeight="2px" android:maxHeight="2px"
        android:layout_gravity="top" android:src="@drawable/horizontal_bar"
        android:scaleType="fitXY" android:layout_weight="1"
        android:layout_width="fill_parent" />
    <LinearLayout android:orientation="horizontal"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:layout_weight="1">
        <ImageView android:src="@drawable/vertical_bar"
            android:minWidth="2px" android:maxWidth="2px" android:scaleType="fitXY"
            android:layout_gravity="left" android:layout_width="wrap_content"
            android:layout_height="fill_parent" android:layout_weight="1" />
        <TextView android:text="testing" android:layout_height="fill_parent"
            android:layout_width="fill_parent" android:paddingLeft="15px"
            android:textStyle="bold" android:textColor="@color/grey"
            android:textSize="20px" android:layout_weight="1"
            android:layout_gravity="center_horizontal|center" />
        <TextView android:text="blablabla" android:layout_height="fill_parent"
            android:layout_width="fill_parent" android:paddingLeft="15px"
            android:textStyle="bold" android:textColor="@color/grey"
            android:textSize="20px" android:layout_weight="1"
            android:layout_gravity="center_horizontal|center" />
        <TextView android:text="0000" android:id="@+id/number"
            android:layout_height="fill_parent" android:layout_width="fill_parent"
            android:layout_gravity="left" android:textStyle="bold"
            android:textColor="@color/green" android:textSize="20px"
            android:layout_weight="1" />
        <ImageView android:src="@drawable/vertical_bar"
            android:minWidth="2px" android:maxWidth="2px" android:scaleType="fitXY"
            android:layout_gravity="right" android:layout_width="wrap_content"
            android:layout_height="fill_parent" android:layout_weight="1" />
    </LinearLayout>
    <ImageView android:layout_height="wrap_content"
        android:minHeight="2px" android:maxHeight="2px"
        android:layout_gravity="top" android:src="@drawable/horizontal_bar"
        android:scaleType="fitXY" android:layout_weight="1"
        android:layout_width="fill_parent" />
</LinearLayout>

Where horizontal_bar is a image with 6x4 and vertical_bar is a image with 4x6. This image needs to be stretch to be able to became a border.

Any idea why the LinearLayout is going out of the screen size?

A: 

Your

<LinearLayout android:orientation="horizontal"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:layout_weight="1">

should have vertical orientation.

Macarse
Hi,It's horizontal. The first LinearLayout is vertical because I want to add lines for every new entry.Then, the second LinearLayout is horizontal because I need to add two elements in the same line. In this case, three texts needs to be in the same line. If I change to vertical, then these texts will be in a separate line each.Thanks for your help!
joao
@joao: Can you upload an image done in paint or something like that drawing the layout your are trying to archieve?
Macarse