我希望两个TextView
元素并排显示(在列表项中),一个元素向左对齐,一个向右对齐.就像是:
|<TextView> <TextView>|
Run Code Online (Sandbox Code Playgroud)
(|
代表屏幕的四肢)
但是,TextView
左侧的内容可能太长而无法放在屏幕上.在这种情况下,我想让它椭圆形但仍然显示完整的权利TextView
.就像是:
|This is a lot of conte...<TextView>|
Run Code Online (Sandbox Code Playgroud)
我在此进行过多次尝试,同时使用LinearLayout
和RelativeLayout
,和我想出了唯一的解决办法是使用RelativeLayout
,把一个marginRight
在左边TextView
足够大的权明确TextView
.但是,你可以想象,这不是最佳选择.
还有其他解决方案吗?
最终LinearLayout
解决方案:
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:inputType="text"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="0"
android:layout_gravity="right"
android:inputType="text"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
旧的,TableLayout
解决方案:
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:shrinkColumns="0"
>
<TableRow>
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
/>
<TextView android:id="@+id/date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"
android:ellipsize="none" …
Run Code Online (Sandbox Code Playgroud) 它在TableLayout的文档中说"单元格可以跨越列,就像它们可以在HTML中一样".但是,我找不到任何办法.
具体来说,我有一行有两列,另一行有一列.我希望一列行跨越整个表.看起来很简单,但我没有看到它.
我有以下问题跨越动态添加行到滚动视图内的TableLayout.行遵循以下模式:
第1行:整个表格上的单元格
第2行:两个单元格
第3行:整个表格上的单元格
...
行N:两个单元格
问题是跨越行的一个单元格的行实际上根本不跨越.它到达屏幕中间的某个点,只是在高处包裹.
以下是Android 2.3.3下的问题的屏幕截图:
请注意,下面的示例过于简单(但仍然跨越不起作用).他们准备尝试 - 只需创建文件.我调试了,似乎布局参数在某种程度上消失了.此外,如果TableLayout在main.xml文件中是硬编码的,那么没有问题.不幸的是,我需要动态生成视图.
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
public class TestProject extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TableLayout table = new TableLayout(this);
ScrollView contentHolder = (ScrollView) findViewById(R.id.scrollView1);
contentHolder.addView(table, new TableLayout.LayoutParams(
TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
TableRow row1 = (TableRow) View.inflate(this, R.layout.table_span_row, null);
TableRow.LayoutParams rowSpanLayout = new TableRow.LayoutParams(
TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
rowSpanLayout.span = 2;
table.addView(row1, rowSpanLayout);
TableRow row2 …
Run Code Online (Sandbox Code Playgroud)