Ernest Lee
Ernest Lee

Reputation: 95

How to Align Text in Android TextView

I have a TextView in my application. I want to align 2 separate text one ontop of the other. But have no idea how. Any suggestions ?

Text code that is to be displayed:

String[] product_showcase_list = new String[] {

"Product Name 产品名称 : Office Chair 1 " +
"Product Serial 产品号码 :0C012345", 
 ...
}

code that is used to call out String text:

label_col_1_datatab3.setText(product_showcase_list[cnt]);

Currently, what is being displayed on the screen:

Product Name 产品名称 : Office Chair 1 Product Serial 产品号码 :0C012345

How it is needed to be displayed:

Product Name 产品名称 : Office Chair 1 
Product Serial 产品号码 :0C012345

Upvotes: 0

Views: 98

Answers (2)

codePG
codePG

Reputation: 1744

Within your loop, change as below.

String temp = product_showcase_list[cnt] + "\n"
label_col_1_datatab3.setText(temp);

Hope it helps!

Upvotes: 1

Juan Aguilar Guisado
Juan Aguilar Guisado

Reputation: 1701

  • Try adding "\n" after your number one. In your String

"Product Name 产品名称 : Office Chair 1 \n" + "Product Serial 产品号码 :0C012345"

  • Or Use two TextViews in a LinearLayout or ListView

Upvotes: 1

Related Questions