当标记可见时,我正在尝试在FrameLayout中显示TextView。
如下面的代码所示:
FrameLayout frameLay = new FrameLayout(context); FrameLayout.LayoutParams layoutParamsFrame = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.FILL_PARENT); frameLay.setLayoutParams(layoutParamsFrame); TextView theText = new TextView(context); theText.setText("text_test"); theText.setTextColor(Color.WHITE); theText.setTypeface(Typeface.DEFAULT_BOLD); LayoutParams layoutParamsText = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); theText.setLayoutParams(layoutParamsText); theText.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM); first = true; frameLay.addView(theText);
这对我不起作用。标记是可见的,我执行此代码,但没有任何反应。 我怎样才能解决这个问题?
答案 0 :(得分:0)
你可以阅读这个post它解释了如何将TextView添加到FrameLayout
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
On Error Resume Next
Dim xRg As Object
For Each xRg In Selection.Cells
xRg.Value = DateClicked
Next xRg
Unload Me
End Sub
Private Sub UserForm_Initialize()
If IsDate(ActiveCell.Value) Then
Me.MonthView1.Value = ActiveCell.Value
End If
End Sub
所以基本上你必须添加 FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER);
((FrameLayout) findViewById(R.id.mainLayout)).addView(mEditText, params);
两个参数
所以变成了
frameLay.addView(theText,layoutParamsText);