2016-12-28 95 views
2

[setLineSpacing](https://developer.android.com/reference/android/widget/TextView.html#setLineSpacing(float,float))在預棒棒糖中不起作用。預棒棒糖線間距實際上也會影響線列的線高。修改線條之間的間距

前棒棒堂:

Prelolipop

棒棒糖及更高版本:

Lollipop

有沒有人發現了一個解決方案?一個可能的解決方案可以定心內線文本,like css

css

代碼:

<Button 
    android:id="@+id/button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Hello \n World!" 
    android:lineSpacingMultiplier="2"/> 
+0

你c一個使用特定的字體和大小在xml中定義如下:android:focusable =「true」 android:fontFamily =「sans-serif」 android:textStyle =「bold」 android:typeface =「normal」android:textSize = 「25dp」根據您的選擇 –

+0

'android:textSize'不適合我,因爲我需要行間距 – neworld

+0

請分享您的代碼,我需要看看您使用的是什麼。 –

回答

0

你可以試試這個

您可以在XML文件中使用lineSpacingExtra和lineSpacingMultiplier 。

android:lineSpacingMultiplier="1.2" 

或大於1的數

android:lineSpacingExtra="xxdp" 

這對我的作品櫃面編輯文本(多)和按鈕。 希望它可以幫助你走出

+0

不幸的是,行間距增加了預棒棒糖設備上最後一行下方的額外空間[請參閱附件中的問題](https://i.stack.imgur.com/9MnI3.png) – neworld

0

嘗試了這一點本作按鈕:

首先是按鍵

<Button 
     android:id="@+id/btn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Change Fourth TextView Line Spacing" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentBottom="true" 
     /> 

現在的Java代碼的XML文件中的代碼:

private Button mButton; 

     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_main); 

      // Get the application context 
      mContext = getApplicationContext(); 

      // Get the activity 
      mActivity = MainActivity.this; 


mButton = (Button) findViewById(R.id.btn); 

// Programmatically set the line spacing of fourth TextView 

mTextViewFourth.setLineSpacing(0,1.5f); 

} 

在這個間距是以編程方式完成的。這是示例代碼。希望它可以幫助你

+0

以編程方式設置間距與通過xml設置間距相同。它修改了線條高度,而不是預先棒棒糖設備中線條之間的間距。 – neworld

+0

好的讓我找到其他替代方法 –

+0

嘿,你可以做一件事情,把一個編輯文本做成一個按鈕,因爲上面的解決方案適用於編輯文本,然後你可以用這種方式添加編輯文本的監聽器,你的編輯文本將表現得很好像一個按鈕和間距問題也將得到解決。我做了編輯文本看幾次按鈕。你可以嘗試這種替代希望,這可以幫助你 –