我正在開始使用Android。我無法獲得簡單的佈局。在Android佈局中對齊左側和右側邊的文字瀏覽
我想用一個LinearLayout
在單排定位兩個TextViews
。一個TextView
在左側,另一個在右側(類似於float:left,float:right在CSS中)。
這是可能的,或者我需要使用不同的ViewGroup
或進一步佈局嵌套來完成呢?
這是我到目前爲止有:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="horizontal" android:padding="10sp">
<TextView android:id="@+id/mytextview1" android:layout_height="wrap_content" android:text="somestringontheleftSomestring" android:layout_width="wrap_content"/>
<TextView android:id="@+id/mytextview2" android:layout_height="wrap_content" android:ellipsize="end"
android:text="somestringontheright" android:layout_width="wrap_content"/>
</LinearLayout>
爲了防止重疊的內容,也可能要加上 '機器人:layout_toLeftOf = 「@ + ID/mytextview2」' 以第一的TextView – 2010-11-19 22:11:18
對於動態表,你可以這樣做: TableRow.LayoutParams col1Params = new TableRow.LayoutParams(); \t \t //結束該行的內容 \t \t col1Params.height = LayoutParams。包裝內容; \t \t col1Params.width = LayoutParams.WRAP_CONTENT; \t \t \t \t //設置重力到中心柱的重力 \t \t col1Params.gravity = Gravity.LEFT; – siddhusingh 2014-08-24 10:31:30
謝謝你,你讓我的生活更輕鬆。真正的thx .. – choz 2016-03-27 17:28:02