2016-08-11 3 views
0

Как добавить вертикальные линии слева от моего текста?
Я показываю blockquote html в TextView динамически.Как добавить вертикальные линии слева от моего текста?

refer image.

+0

Вы также можете использовать ** составную ** ('drawableLeft', в данном случае) ** и сохранить дополнительный просмотр. –

+0

вы можете объяснить больше? –

+0

Пожалуйста, google для 'android textview compound drawable' –

ответ

1

Место слева от вашего textView и используйте требуемые размеры и цвет.

 <View 
     android:layout_width="2dp" 
     android:layout_height="100dp" 
     android:background="@color/colorPrimaryDark"></View> 
+0

хотите создать текстовое представление динамически, установить текст из html. –

1

использование

<View android:id="@+id/view" 
      android:layout_height="match_parent" 
      android:layout_width="1dp" 
      android:background="#000000" /> 

использование WebView для Html текста

WebView webview = (WebView)this.findViewById(R.id.webview); 
    webview.getSettings().setJavaScriptEnabled(true); 
    webview.loadDataWithBaseURL("", data, "text/html", "UTF-8", ""); 

вот код, который вы хотите

 String a = "You can "; 
     String b = "change" ; 
     String c = "like this" ; 
     String d = "if want to make it bold"; 
     String sourceString = a + " " + "<b>" + b + "</b>" + " " + c + " " + "<b>" + d + "</b>"; 
     textView.setText(Html.fromHtml(sourceString)); 

это будет выглядеть

Вы можете изменить как этот , если хотите, чтобы сделать его полужирным

+0

хотите создать текстовое представление динамически, установить текст из html. –

+0

проверка отредактированный ответ @BincyBaby –

+0

без использования WebView –

1

Вы можете использовать View:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="10dp" 
    android:orientation="horizontal"> 

    <View 
    android:layout_gravity="right" 
    android:background="#000000" 
    android:layout_width="2dp" 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="20dp" 
    android:layout_height="match_parent" /> 

    <TextView 
    android:text="balblalblablalblablalblalb" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

</LinearLayout> 

Это будет выглядеть так:

enter image description here

За показ Html вы можете сделать следующее:

yourTextView.setText(Html.fromHtml("your html string")); 
+0

хотите создать текстовое представление динамически, установить текст из html. –

+0

Вы можете создать 'TextView' динамически, как:' TextView t = новый TextView (контекст); 'чем установить' LayoutParams' на основе ваших потребностей – hrskrs

0
Step 1: Add a Linear layout in a layout. 
<LinearLayout 
    android:id="@+id/linear_layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_margin="10dp"> 

</LinearLayout> 
step2:In Activity , create TextView and a View dynamically add to linear layout 
LinearLayout mylayout = (LinearLayout) findViewById(R.id.linear_layout); 

    TextView text = new TextView(this); 
    text.setText("Testing"); 

    View view = new View(this); 
    view.setBackgroundColor(getResources().getColor(R.color.black)); 
    view.setLayoutParams(new LinearLayout.LayoutParams(5, LinearLayout.LayoutParams.MATCH_PARENT)); 

    mylayout.addView(view,0); 
    mylayout.addView(text,1); 

Надеюсь, это поможет!

 Смежные вопросы

  • Нет связанных вопросов^_^