我正在显示一个带有行的TableLayout,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<TableRow
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/one"
android:layout_marginLeft="10dip"
android:textColor="#B0171F" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/one"
android:id="@+id/two"
android:layout_marginLeft="10dip"
android:ellipsize="none"
android:singleLine="false"
android:scrollHorizontally="false"
android:maxLines="10"
android:textColor="@android:color/black" />
</RelativeLayout>
</TableRow>
Run Code Online (Sandbox Code Playgroud)
我正在使用我能在这里找到的所有东西,并且可以想到允许文本包裹在许多行上,但无济于事:文本总是被强制为一行,从屏幕上运行.我在这里工作在TableRow中可能很重要,据我所知,这个网站没有得到处理.
那么,如何强制我的第二个TextView包装到多行呢?
我想知道如何TextView在几行中显示其内容而不用硬编码XML中的宽度.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
android:text="Long multiline text"/>
<TextView
android:textColor="@color/text_color"
android:layout_width="130dp"
android:layout_height="wrap_content"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
任何想法都欢迎.
编辑:我的问题是,当文本超过设置的宽度(因为它到达屏幕的末尾)时,文本的一部分不会显示.我希望文本分为两行
我在我的Android应用程序中定义了如下ListPopupWindow.
ListPopupWindow listPopupWindow;
listPopupWindow = new ListPopupWindow(RootView.this);
listPopupWindow.setAdapter(new ArrayAdapter<String>(RootView.this,
R.layout.push_list_item, pushMessages));
listPopupWindow.setAnchorView(bEvents);
listPopupWindow.setWidth(300);
listPopupWindow.setHeight(400);
listPopupWindow.setModal(true);
listPopupWindow.show();
Run Code Online (Sandbox Code Playgroud)
上面引用的布局的XML如下所示.
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FF0000"
android:paddingLeft="6dp"
android:textSize="12sp"
android:maxLines="3"
android:lines="3"
android:ellipsize="end"
android:textStyle="bold" />
Run Code Online (Sandbox Code Playgroud)
当我得到一个更大的文本时,即使我在XML中指定了正确的属性,文本也只是剪辑而不是换行.任何人都可以帮助我理解这里发生的事情,并为我的问题提出解决方案.
谢谢..
我正在创建这样的日期格式:
SimpleDateFormat sdf =new SimpleDateFormat("MMM d, EEE, h:mm a");
Run Code Online (Sandbox Code Playgroud)
我需要在日期,月份和时间之间划一条新线
thus ,sep 6
4:25pm
Run Code Online (Sandbox Code Playgroud)
所以我做了以下更改:
SimpleDateFormat sdf =new SimpleDateFormat("MMM d, EEE,"+"\n"+" h:mm a");
Run Code Online (Sandbox Code Playgroud)
它没有给我任何东西只是它在一行中创建它像这样:
thus ,sep 6 4:25pm
Run Code Online (Sandbox Code Playgroud)
所以我采用了这样的格式对象
SimpleDateFormat sdf =new SimpleDateFormat("MMM d, EEE,");
SimpleDateFormat sdf1 =new SimpleDateFormat(" h:mm a");
Run Code Online (Sandbox Code Playgroud)
并做到了这一点:
sdf.format(calendar.getTime())+"\n"+sdf1.format(calendar.getTime())
Run Code Online (Sandbox Code Playgroud)
但它又给出了相同的结果
thus ,sep 6 4:25pm
Run Code Online (Sandbox Code Playgroud)
日历是一个日历对象.任何帮助将不胜感激!
这是这个问题的后续问题:
我有一个 TextView 声明如下:
<TextView
android:id="@+id/myTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:gravity="left|start"
android:text="TextView"
android:singleLine="false"/>
Run Code Online (Sandbox Code Playgroud)
在代码中我设置了一个长文本,文本视图将它显示为一个长单行而不是将其拆分为多行。链接问题中接受的答案建议设置android:maxWidth属性,但我不想那样做。如果文本的长度超过文本视图声明中设置的 0.4 权重,我希望文本行自动中断。有没有办法做到这一点而不使用恒定大小?
根据要求,这是带有父级的文本视图:
<LinearLayout
android:id="@+id/linearLayoutBottomData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayoutTopData"
android:layout_marginBottom="5dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="@+id/myTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:gravity="left|start"
android:text="TextView"
android:textColor="@android:color/black"
android:textSize="@dimen/large_font_size"
android:singleLine="false"/>
<TextView
android:id="@+id/myTextView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:gravity="left|start"
android:text="TextView"
android:textColor="@android:color/black"
android:textSize="@dimen/large_font_size"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)