2014-09-23 86 views
6

我想增加文本和下劃線之間的距離。我可以更改線條高度,但我不會更改文字之間的高度,也不會強調底線。我該如何操作?如何增加TextView Android中的文本和下劃線之間的空間?

private static final String FONTH_PATH = "fonts/Brandon_bld.otf"; 

... 

selectTextView = (TextView) findViewById(R.id.selectTextView); 
selectTextView.setTypeface(font); 

SpannableString content = new SpannableString(getResources().getString(R.string.select_your_prove_type)); 
content.setSpan(new UnderlineSpan(), 0, content.length(), 0); 
selectTextView.setText(content); 

... 

和XML文件

<TextView 
android:id="@+id/selectTextView" 
android:layout_width="match_parent" 
android:layout_height="0dp" 
android:layout_weight="536" 
android:gravity="left" 
android:lineSpacingMultiplier="0.8" 
android:text="@string/select_your_prove_type" 
android:textColor="@color/Blue" 
android:textSize="@dimen/select_size" /> 
+0

我不知道答案,也許linespacingextra屬性應該這樣做,但爲什麼你的重量屬性具有值536'android:layout_weight =「536」'? – 2014-09-23 12:19:28

+0

lineSpacingExtra不適用於此問題。我根據iPhone psd分割屏幕。身高是1136像素在這PSD和我的根佈局weightSum也是1136. – smihilor 2014-09-23 22:24:46

回答

0

您可以添加一個可繪製文件(在我來說,我已經創建了一個影子)定製的強調,並設置了這個風俗強調

android:background="@drawable/shadow_file.xml" 

之後,在您的EditText中添加填充,您可以在該行和文本之間添加更多空間。

android:paddingBottom="@dimen/underline_space" 

並在您的dimens.xml文件中定義此維度。

這對我的作品,我希望你也:)

+0

謝謝你分享你的答案,但我不明白。你創建了一個自定義的edittext嗎? @jgarciabt – smihilor 2015-02-13 12:01:26

+0

對不起,我的簡短解釋。我有一個默認的EditText,但有一個自定義下劃線。你可以添加一個可繪製文件的自定義下劃線(在我的情況下,我創建了一個影子),並使用android:background =「@ drawable/shadow_file.xml」來設置這個自定義下劃線。在這之後,您可以在該行和文本之間添加更多空格。 – jgarciabt 2015-02-13 14:45:55

+0

可以請你分享shadow_file.xml或解釋如何添加它? – Dhasneem 2015-03-11 13:14:27

1

好這裏是一個更完整的答案:

在你styles.xml,添加一個樣式:

<style name="MyTour.HeadingText"> 
    <item name="android:background">@drawable/tour_header_line_layerlist</item> 
</style> 

現在創建一個帶有內容的tour_header_line_layerlist.xml文件:

<layer-list 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:top="20dp" android:drawable="@drawable/tour_header_line"/> 
</layer-list> 

上面將設置一個邊距20dp的頂線(提取出來給dimen.xml的完整性)

現在創建相應的tour_header_line.xml:

<shape android:shape="line" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
<stroke 
     android:width="1dp" 
     android:color="@color/tour_subheading_color" /> 

現在引用風格在你的控制:

<TextView 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:text="@string/tour_1_heading_text" 
      android:id="@+id/heading_text" android:layout_gravity="center_horizontal" 
      style="@style/MyTour.HeadingText" //notice this 
      android:layout_marginTop="@dimen/margin_large"/> 

讓我知道你是否還有其他問題!

+0

這對於android:top =「20dp」非常有效,當我們改變最高價值時,爲什麼它不工作? – Dilip 2015-06-17 12:18:04

4

只需使用

paddingBottom來

如下

  <android.support.design.widget.TextInputLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 

      <EditText 
       android:id="@+id/fragment_activity_edit_desc" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:paddingBottom="16dp" 
       android:hint="Description" 
       android:textSize="34sp" 
       tools:text="Secret Death Ray Design"/> 


     </android.support.design.widget.TextInputLayout> 
+0

您是否使用TextView?我試過了,它不適用於TextView @Uzair Mohammad – smihilor 2016-02-23 07:51:57

-1

中的EditText XML添加這些行

機器人:includeFontPadding = 「真」 的android:paddingBottom來=「20dp」

相關問題