android 动态设置textview的边距,添加边距为动态的Android的TextView(Adding Margins to a dynam...

我已经通过这个以前的答案一堆看,并试图标记为工作的代码,但到目前为止,我没有什么可以做说服我完全填满屏幕从左至右创建于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的。

我试过去除形状等..

有任何想法吗?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值