我已经查看了一堆以前的答案,并尝试了标记为工作的代码,但到目前为止,我做的任何事都不能说服我在创建时从填充从左到右完全屏幕。我想在两边添加类似于普通Toast的保证金。之后,我可以为形状添加阴影。为一个动态的Android TextView添加页边距
这里我的表单布局。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rel_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/tv1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center_vertical|center_horizontal"
android:text="@string/hello_world"
android:textColor="@color/holobrightblue"
android:textSize="48sp"
android:textStyle="bold"
tools:context=".MainActivity" />
</RelativeLayout>
..和我的代码
textView = new TextView(m_Context);
RoundRectShape rs = new RoundRectShape(new float[] { 10, 10, 10, 10, 10, 10, 10, 10 }, null, null);
ShapeDrawable sd = new ShapeDrawable(rs);
sd.setAlpha(m_opacity);
textView.setBackgroundDrawable(sd);
textView.setTextColor(m_txtcolor);
textView.setText(toasttitle+"\n"+toastmessage);
textView.setBackgroundColor(Color.BLACK);
textView.setPadding(10,10,10,10);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
lp.setMargins(60, 0, 60, 0);
textView.setLayoutParams(lp);
toastView = new Toast(m_Context);
toastView.setView(textView);
toastView.setDuration(m_toastlen);
toastView.setGravity(m_screengravity, 0,0);
toastView.show();
如前所述,没有什么我已经从其他的解决方案试图似乎填满所有的卧式空间说服TextView的。
我试过去除那个形状等...
任何想法?
填充不会解决这个问题,因为它会被应用于文本TextView的内部,使文字和边框之间的空间将得到increased.The人想要完整TextView以居中或移动为屏幕边框的给定值 – 2012-08-01 11:18:44
请参阅我编辑的答案 – 2012-08-01 11:19:10
感谢您接受我的评论+ vely.Still,问题将保留,因为填充将应用于TextView中的文本。你知道我在说什么?因为填充是应用于TextView的,所以文本会被填充。 – 2012-08-01 11:22:35