开发者

LinearLayout - How to get text to be on the right of an icon?

Bit of a newbie when it comes to android, only been working on it properly for a few days but even after all the searching I've done im stumped and nobody seems to know how to help me. I have this so far:

http://img263.imageshack.us/i/sellscreen.jpg

How can I move the text to be besides each icon rather than underneath it? Hoping the gallery won't be moved either. Here is the code i have:

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

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scroller"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true" >

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

    <Gallery xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gallery"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>

    <ImageView 
     android:id="@+id/test_image"
     android:src="@drawable/icon"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"/>

    <TextView  
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="The offcial UK driving theory test application. Over 190 questions."
     />

    <ImageView 
     android:id="@+id/test_image"
     android:src="@drawable/icon"

     android:layout_width="wrap_content"
     android:layout_height="wrap_content"/>

    <TextView  
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="The offcial UK driving theory test application. Over 190 questions."/>

    <ImageView 
     android:id="@+id/test_image"
     android:src="@drawable/icon"

     android:layout_width="wrap_content"
     android:layout_height="wrap_content"/>

    <TextView  
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="The offcial UK driving theory test application. Over 190 questions."/>

    <ImageView 
     android:id="@+id/test_image"
     android:src="@drawable/icon"

     android:layout_width="wrap_content"
     android:layout_height="wrap_content"/>

    <TextView  
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="The offcial UK driving theory test application. Over 190 questions."/>

    <ImageView 
     android:id="@+id/test_image"
     android:src="@drawable/icon"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     />

    <TextView  
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="The offcial UK driving theory test application. Over 190 questions."
        />

    </LinearLayout>

</ScrollView>

Top half of my code doesn't seem to be showing for some reason but it's just the opening of the linear layout. I will be f开发者_StackOverflow社区orever grateful to anyone that can help, i've been racking my brains for days and getting nowhere. Really getting stressed out by it. Thanks in advance!!


You need to wrap each ImageView/TextView pair in a linearlayout

<LinearLayout 
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
    <ImageView 
     android:id="@+id/test_image"
     android:src="@drawable/icon"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"/>

    <TextView  
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="The offcial UK driving theory test application. Over 190 questions."
     />
</LinearLayout>

It's also pretty clear that you didn't ask anyone who knew android, because this is pretty trivial.


Have you read through the android layout tutorials? Lots of stuff on the dev site, like declaring layout, common layout objects, and the hello views tutorials.

There are a number of ways to accomplish this, depending on your goals.

Is it a list of items of unknown size that may want to scroll? Use a ListView. You can provide a custom layout to the ListView with your things side by side.

Do you have a finite set of things? Use a RelativeLayout. Tell each TextView to layout below the one above, and each ImageView to layout to the right of it's TextView.

You could also accomplish that with nested LinearLayouts, one vertical and a bunch of horizontal, but that is less efficient than using a RelativeLayout.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜