dieblazin
dieblazin

Reputation: 25

linear layouts not spacing correctly

Hey im having trouble with these linear layouts in android xml. initially i did them in a relative layout and it worked fine, but after some research i discovered that relative layouts inside of a scrollview doesnt work supposedly. so now after much tweaking my imageview shows up but has a huge margin above and below it and my textview doesnt even show up aside from being where its supposed to in the graphics editor but blank.

so whats wrong? should i even be using a linear layout?

this is roughly what its supposed to look like http://www.mediafire.com/view/?z945tz2vrb2x46t

and this is what it looks like after Abdul and Ralgha's help as well as setting the base linear layout's height to wrap content http://www.mediafire.com/view/?px17q2z3yyeo8az

Thanks

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/LinearLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        >
        <TextView 
            android:id="@+id/today"
            android:src="@string/today"
            android:textSize="30dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            />
        <ImageView
            android:id="@+id/image1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/weeklylist_blocks"
            />

     </LinearLayout>
</ScrollView>

</LinearLayout>


`![screwed up layout][1]

Upvotes: 2

Views: 131

Answers (3)

Khantahr
Khantahr

Reputation: 8548

Don't worry about weight right now, leave it removed. In your TextView, change "android:src" to "android:text" (without the quotes naturally). If that alone doesn't solve it, remove the textSize line and see what happens. If that works, then you can start playing with sizes (and weights if needed).

Also, textSize should be given in sp rather than dp. sp is for text, dp is for everything else, though that's not what is causing your problem.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/LinearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >
        <TextView 
            android:id="@+id/today"
            android:textSize="30sp"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:text="@string/today"
            />
        <ImageView
            android:id="@+id/image1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/weeklylist_blocks"
            />

    </LinearLayout>
</ScrollView>

Upvotes: 1

Abdul Rahman
Abdul Rahman

Reputation: 2089

Its works like charm, Use the following coding to achieve your thing:

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

<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:fillViewport="true" >

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

    <TextView 
        android:id="@+id/today"
        android:src="@string/today"
        android:textSize="30sp"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:text="@string/today"
        />

    <ImageView
        android:id="@+id/image1"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:contentDescription="@string/nissan"
        android:src="@drawable/weeklylist_blocks" />

 </LinearLayout>
</ScrollView>

</LinearLayout>

Upvotes: 0

dorjeduck
dorjeduck

Reputation: 7804

android:layout_weight="1"

might be the cause of your problems

Upvotes: 1

Related Questions