回答
您可以使用setLineSpacing來設置你的TextViews一個足夠大的差距,重疊它們,然後把它翻譯這樣一個在其他的字裏行間顯示出來。
我想補充一些細節,你必須調整兩個TextViews邊緣,你會想用一個佈局,使您可以重疊的意見,以及查看背景設置爲透明的,但在整個這是在可能是實現效果的最簡單方法之一。 – TheIT
試試這個代碼。 您可以設置TextView的lineSpacingExtra屬性,並可以使用相對佈局來重疊它們。在此之後,你中央社你的文本視圖的一組屬性相應
In your xml define text view properties like this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
tools:context=".MainActivity" >
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is Text 1. This is Text1. This is Text 1. This is Text1. This is Text 1. This is Text1"
android:lineSpacingExtra="20dp"
android:textColor="#5F4C0B"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="26dp"
android:lineSpacingExtra="26dp"
android:text="This is Text 2. This is Text2. This is Text2. This is Text2. This is Text2. This is Text2"
android:textColor="#B40404"
android:textSize="20sp" />
</RelativeLayout>
你會得到這樣的
輸出接受的答案,如果你發現它有用
爲什麼有人會嘗試你的代碼?你提出什麼解決方案來解決特定問題?包括更多的細節來獲得投票和讚賞。 #提示 –
感謝您的建議@Paresh。下次我會記住它。 –
乾杯!快照看起來不錯。 –
您可以動態創建此視圖,
在主要活動寫入以下代碼
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RelativeLayout rl = new RelativeLayout(this);
RelativeLayout.LayoutParams text1 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
text1.setMargins(0, 0, 0, 0);
RelativeLayout.LayoutParams text2 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
text2.setMargins(0, 26, 0, 0);
LinesTextView tv1 = new LinesTextView(this, null);
tv1.setText("This is Text 1. This is Text 1. This is Text 1. This is Text 1. This is Text 1. This is Text 1.");
tv1.setLineSpacing(20.0f, 1.0f);
tv1.setLayoutParams(text1);
tv1.setTextSize(24.0f);
tv1.setTextColor(getResources().getColor(android.R.color.darker_gray));
LinesTextView tv2 = new LinesTextView(this, null);
tv2.setText("This is Text 2. This is Text 2. This is Text 2. This is Text 2. This is Text 2. This is Text 2.");
tv2.setLineSpacing(25.0f, 1.0f);
tv2.setLayoutParams(text2);
tv2.setTextSize(18.0f);
tv2.setTextColor(getResources().getColor(android.R.color.black));
rl.addView(tv1);
rl.addView(tv2);
this.setContentView(rl);
}
}
在LinesTextView類編寫如下代碼
public class LinesTextView extends TextView
{
private Rect mRect;
private Paint mPaint;
// we need this constructor for LayoutInflater
public LinesTextView(Context context, AttributeSet attrs) {
super(context, attrs);
mRect = new Rect();
mPaint = new Paint();
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(0x800000FF);
}
@Override
protected void onDraw(Canvas canvas) {
int count = getLineCount();
Rect r = mRect;
Paint paint = mPaint;
for (int i = 0; i < count; i++) {
int baseline = getLineBounds(i, r);
canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint);
}
super.onDraw(canvas);
}
}
檢查屏幕拍攝
設置文本顏色,樣式,邊緣和大小相應。
- 1. 如何從一個文本框顯示文本到另一個
- 2. Xamarin Forms - 如何在一個xaml內顯示另一個內容
- 3. 嵌套在第一個div內的jQuery顯示文本
- 4. 如何顯示一個圖像五秒鐘然後顯示另一個(Android Studio)
- 5. 如何顯示一個頁面的內容到另一個頁面的內容
- 6. 無法顯示內的另一個
- 7. Android:如何在另一個xml的textview中嵌入一個類?
- 8. android studio - 如何讓文本從一個活動到另一個?
- 9. 如何製作一個jqgrid顯示內嵌鄰近另一個jqgrid或只是一個div?
- 10. 顯示兩個圖像一個在另一個之上的Android
- 11. 如何在另一個顯示分數文本編號?
- 12. 一個接一個地顯示div,另一個顯示div
- 13. 顯示一個文本框
- 14. 如何在另一個DIV內嵌顯示固定大小的DIV?
- 15. 當JSONArray給出一個空值時顯示一個文本 - android
- 16. 在另一個框架內顯示iframe
- 17. 如何將3個文本框內容顯示在按鈕單擊的另一個文本框中
- 18. 如何顯示另一個表中的一個表的列
- 19. 如何從一個div顯示一整行到另一個
- 20. 在android的另一個頂部顯示一個圖像
- 21. 如何讓一個文本隱藏另一個文本。
- 22. 顯示內另一
- 23. 嵌入另一個Eclipse編輯器內的文本編輯器
- 24. 如何顯示的內容另一塊
- 25. 如何顯示一個網站的內容到另一個網站
- 26. jQuery:如何顯示文本並隱藏然後顯示另一個?
- 27. 如何在另一個文件中顯示一個xml文件。 XML的另一個XML
- 28. 如何顯示另一個命令
- 29. 如何顯示另一個元素下的一個元素?
- 30. 顯示一個畫布到另一個
只要把它們放在一個下面。這是佈局的目的。您可以使用RelativeLayout或垂直LinearLayout輕鬆完成此操作。 –
您是使用XML還是編程創建TextView? –