2014-10-29 54 views
0

我有很長的文字多行..在Android中多行的textview適合屏幕多長時間?

所以,我曾嘗試: -

activity_into.xml

<?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="fill_parent" 
android:background="@drawable/bck" 
android:orientation="vertical" > 
<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="overview" 
    android:textColor="@color/white" 
    android:textStyle="bold|italic" 
    android:layout_marginTop="55dp"/> 
<TextView 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/intro" 
    android:textColor="@color/white" 
    android:layout_marginTop="10dp"/> 

這裏「@字符串/介紹「是一個包含多行的長文本。 通過上面的代碼,我的文本: - Like this ,, 這個文本不適合屏幕..

我想用一個好的文本style..How左側和右側之間的小空間,我可以做到這一點? ????

+0

用於間距使用margin_left和margin_right。如果你想改變字體..添加它的樣式和使用android:textstyle屬性 – Naufal 2014-10-29 04:43:01

+0

添加margin_left和margin_right – 2014-10-29 04:43:03

回答

0

呦需要應用填充給在兩側空間:

<?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="fill_parent" 
android:background="@drawable/bck" 
android:orientation="vertical" 
android:paddingLeft="10dip" 
android:paddingRight="10dip"> 
    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="overview" 
     android:textColor="@color/white" 
     android:textStyle="bold|italic" 
     android:layout_marginTop="5dp"/> 
    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/intro" 
     android:textColor="@color/white" 
     android:layout_marginTop="10dp"/> 
</LinearLayout> 

你可以給android:padding="10dip",如果你需要給相同墊在所有方向。

+0

感謝兄弟..它太棒了......但我不能接受你的答案..因爲我只有8分.. – 2014-10-29 04:46:33

+0

@SomChatterjee upvoting需要回購。你可以接受:)點擊左邊的右邊打勾。 – 2014-10-29 04:48:21

+0

對不起它說你需要15個聲望才能投票 – 2014-10-29 04:50:57

1

試試下面的代碼:

<?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="fill_parent" 
android:background="@drawable/bck" 
android:paddingLeft="10dp" 
android:paddingRight="10dp" 
android:orientation="vertical" > 
<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="overview" 
    android:textColor="@color/white" 
    android:textStyle="bold|italic" 
    android:layout_marginTop="5dp"/> 
<TextView 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/intro" 
    android:gravity="center" 
    android:textColor="@color/white" 
    android:layout_marginTop="10dp"/> 
+0

Noooo .. ....我不想要那種類型..見上面的答案由「MysticMagic」 – 2014-10-29 04:49:11

0

試試這個辦法,希望這將幫助你解決你的問題。

將ScrollView作爲第二個TextView的父項,所以當文本輸出屏幕時,它將應用滾動並給出您的左右填充到ScrollView,這裏我也給ScrollView權重,因此它將在第一個Textview內容之後佔用休息高度。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/bck" 
    android:orientation="vertical"> 
    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="overview" 
     android:textColor="@color/white" 
     android:textStyle="bold|italic" 
     android:layout_marginTop="10dp"/> 
    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:layout_marginTop="10dp"> 
    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/intro" 
     android:textColor="@color/white"/> 
    </ScrollView> 
</LinearLayout>