• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps LinearLayout usage

Hello Guys!

It's my first post here and I hope that it will not be the last one! :)

First of all, I already programmed for android, but using absoluteLayout (it's so simple! :P ), now, I'm moving to dynamic positions for obvious reasons (We don't have just few screen sizes now and the future Android's "ipad" are starting to appear with huge screens).

So, my concern here is to understand and work with LinearLayouts. I tried to use the RelativeLayout, but everybody told me to start with the LinearLayouts, because it's simple.

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:
Code:
<?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?

Thanks a lot for your help,
Joao
 
Read the first 2 lines of your post.

Absolute layout is deprecated, don't ever use it ever again pls k thnx
 
Ok read the rest now.

Omg your linear layout is horrible :-p

For what you are attempting to achieve even tho everyone said start with linear,

I would make a framelayout with your borders in and then a linearlayout with everything else inside.

Basically a framelayout dumps everything on top of each other. so your border will be at the back then the linearlayout will be on top. Linearly (one after the other) showing whatever items you put in it
 
Hi,

Maybe I was not clear in my question.
I'm not understanding why the size of the elements are going to outside of the screen.
How can I ""say" that I want to only use the physical screen? Doesn't matter what I add, it will always be inside of the screen.

Thanks,
Joao
 
Hmm I don't think you can. Just think if you had 50 EditText boxes, how would Android force them to show all on one screen? They would have to be drawn off the bottom and as a side note to see them all you would wrap the linearlayout in a scrollview
 
Actually,

I was expecting the screen being divided in 50 parts, in the example that you gave me.
I know that this means that I will not be able to use them. But once that I'm not using the ScrollView, I was expecting this approach.
Right now, without using the ScrollView, I'm not able to see the elements out of the screen, so, there are no reason to have it.
Anyway, about the code above:
The text is very small, it's possible to show the entire 3 parts of text in the screen. But the division made by eclipse is increasing the size of the first word in double. So, the text "testing" is using a space like "testingtesting". And this is causing the other words to be out of the screen.
Any clue why this is happening?

PS: Thanks for your help!

Thanks,
Joao
 
I would advise you explain with screen shots. As your code is impossible to read, I would recommend setting layouts like:
Code:
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/com.blundell"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    >
    <Button
        android:id="@+id/open"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Take Another Pic"
    />
    <com.admob.android.ads.AdView  
      android:id="@+id/ad3" 
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      app:backgroundColor="#000000"
      app:primaryTextColor="#FFFFFF"
      app:secondaryTextColor="#CCCCCC"
      app:keywords="Toy Fun"
    />
    <View
        android:layout_height="20dip"
        android:layout_width="fill_parent"
        android:background="#000000" />
    <com.admob.android.ads.AdView  
      android:id="@+id/ad4" 
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      app:backgroundColor="#000000"
      app:primaryTextColor="#FFFFFF"
      app:secondaryTextColor="#CCCCCC"
      app:keywords="Picture Photo Image"
    />
</LinearLayout>

atleast then you can read what element is doing what, without unlimited scrolling.

Finally I will try an helpyou fix your problem if you do these things :-) but the simpler answer is to used a Framelayout like I said:
Code:
<FrameLayout>
    <LinearLayout>
       <ImageView
          android:id="topBorder"
          />
       <ImageView
          android:id="bottomBorder"
        />
       <ImageView
          android:id="leftBorder"
        />
       <ImageView
          android:id="rightBorder"
        />
     </LinearLayout>
     <LinearLayout>
        <TextView  android:text="testing" />
        <TextView  android:text="testing2" />
    </LinearLayout>
</FrameLayout>

Looks prettier as well :-)
 
Back
Top Bottom