我已经通过这个以前的答案一堆看,并试图标记为工作的代码,但到目前为止,我没有什么可以做说服我完全填满屏幕从左至右创建于runtme TextView的。 我想补充两侧类似于普通面包的余量。 从那以后,我可以添加阴影的形状。

我在这里的形式布局。

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/rel_layout"

android:layout_width="match_parent"

android:layout_height="match_parent" >

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" />

..和我的代码

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的。

我试过去除形状等..

有任何想法吗?

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐