问题
Here I have developed one app. Here I wish to need the o/p like below format:
Artist: artist
Duration: duration
Title: title.
But I got the o/p is:
Artist:
artist
Durstion:
duration
Title:
title
Here I wish to need the above format.
How can I do this?
Here I have used below code for my layout file. But I can't get the my requirement output. So please help me and give me some ideas. please help me
this is my layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/orderinformation"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/payment_method1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5px"
android:text="Artist"
android:textSize="15dip"
android:textStyle="bold" />
<TextView
android:id="@+id/artist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/payment_method1"
android:paddingLeft="75px"
android:text="artist"
android:textColor="#10bcc9"
android:textSize="15dip"
android:textStyle="bold" />
<TextView
android:id="@+id/total1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5px"
android:text="Duration"
android:layout_below="@id/payment_method1"
android:textSize="15dip"
android:textStyle="bold" />
<TextView
android:id="@+id/duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="65px"
android:layout_toRightOf="@+id/total1"
android:text="duration"
android:textColor="#10bcc9"
android:textSize="15dip"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="@id/orderinformation" >
<TextView
android:id="@+id/firstname1"
android:paddingLeft="5px"
android:textSize="15dip"
android:layout_below="@id/total1"
android:text="Title"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/title"
android:text="title"
android:paddingLeft="65px"
android:layout_toRightOf="@+id/firstname1"
android:textSize="15dip"
android:textColor="#10bcc9"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
回答1:
As you are using LinearLayout with orientation as vertical you will get every new layout below the previous Layout. Better would be use RelativeLayout. As android:layout_toRightOf
is a property of RelativeLayout it will have no effect in LinearLayout.
The best in your case would be using TableLayout, just you have to put TextView inside TableRow.
Pseudo code,
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableRow>
<TextView
android:id="@+id/payment_method1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip"
android:text="Artist"
android:textSize="15dip"
android:textStyle="bold" />
<TextView
android:id="@+id/artist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip"
android:text="artist"
android:textColor="#10bcc9"
android:textSize="15dip"
android:textStyle="bold" />
</TableRow>
<TableRow>
<TextView
android:id="@+id/total1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip"
android:text="Duration"
android:textSize="15dip"
android:textStyle="bold" />
<TextView
android:id="@+id/duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip"
android:text="duration"
android:textColor="#10bcc9"
android:textSize="15dip"
android:textStyle="bold" />
</TableRow>
<TableRow>
<TextView
android:id="@+id/firstname1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip"
android:text="Title"
android:textSize="15dip"
android:textStyle="bold" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip"
android:text="title"
android:textColor="#10bcc9"
android:textSize="15dip"
android:textStyle="bold" />
</TableRow>
</TableLayout>
回答2:
Something like this:
<LinearLayout... orientation = vertical>
<LinearLayout... orientation = horizontal>
<TextView title>
<TextView value>
</LinearLayout>
<LinearLayout... orientation = horizontal>
<TextView title>
<TextView value>
</LinearLayout>
</LinearLayout>
or use TableLayout
ps. not a real syntax for layout, just to illustrate the idea
回答3:
Well in my opinion or a beginner, the graphical would very much help you in achieving that. You can just drag and drop the TextView where ever you want.
回答4:
you have to use RelativeLayout, if you want to adjust your textview according to you means
回答5:
Try this This may also help to solve your requirement
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/t2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dip" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/payment_method1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5px"
android:text="Artist"
android:textSize="15dip"
android:textStyle="bold" />
<TextView
android:id="@+id/artist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="65px"
android:text="artist"
android:textColor="#10bcc9"
android:textSize="15dip"
android:textStyle="bold" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp" >
<TextView
android:id="@+id/total1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/payment_method1"
android:paddingLeft="5px"
android:text="Duration"
android:textSize="15dip"
android:textStyle="bold" />
<TextView
android:id="@+id/duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="65px"
android:text="duration"
android:textColor="#10bcc9"
android:textSize="15dip"
android:textStyle="bold" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp" >
<TextView
android:id="@+id/firstname1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/total1"
android:paddingLeft="5px"
android:text="Title"
android:textSize="15dip"
android:textStyle="bold" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/firstname1"
android:paddingLeft="65px"
android:text="title"
android:textColor="#10bcc9"
android:textSize="15dip"
android:textStyle="bold" />
</TableRow>
来源:https://stackoverflow.com/questions/12722246/android-layout-torightof-and-androidlayout-below