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的。
我試過去除形狀等..
有任何想法嗎?
總結
以上是生活随笔為你收集整理的android 动态设置textview的边距,添加边距为动态的Android的TextView(Adding Margins to a dynam...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux设置切换窗口特效,Linux_
- 下一篇: php 聚合和组合,reduce端连接-