[英]How to align Two TextViews next to each other in LinnearLayouts?
[英]How to align TextViews one next to each other from beginning to the end?
我正在創建一個android應用程序,並且我必須顯示例如10個textview-彼此相鄰等等,在多少行中都無所謂,只需自動執行即可。 這張圖片中的內容:
我應該使用哪種布局? 我嘗試了Gridlayout和gridview,但是以某種方式我無法實現這種行為。 有任何想法嗎?
謝謝!
我建議您為此使用一個texView,除非您希望為每個文本(例如文本顏色,背景,字體樣式等)提供不同的UI設計。
如果您不知道文本的數量,則可以使用單個textView並將其設置為串聯的全文文本。
您的文本視圖應支持多行,並且您還可以設置最大行數限制。
示例代碼:
<TextView
android:id="@+id/tvMyText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="false"
android:maxLines="5"
android:textColor="@color/black"
android:textSize="14sp" />
String finalText = "";
String[] yourData = // string your containing all texts
for ( String text : yourData ) {
finalText = text + " "; // add space after every text
}
TextView tvText = (TextView) view.findViewById( R.id.tvMyText );
tvText.setText( finalText );
我不確定該解決方案是否可以完全滿足您的要求...但是您可能會想一想。
您好,這里是使用自定義庫的示例,該庫的行為類似於List GitHubLibrary TagLayout
mFlowLayout.setAdapter(new TagAdapter<String>(mVals) { @Override public View getView(FlowLayout parent, int position, String s) { TextView tv = (TextView) mInflater.inflate(R.layout.tv, mFlowLayout, false); tv.setText(s); return tv; } });
-這將根據數組中文本的大小動態設置您的textview
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.