我可能遗漏了什么,但我找不到一种方法来在指定的索引处添加一个具有特定布局参数的子视图。有
我错过了什么?
addView(View v,LayoutParams lp)
和addView(View v,int index)
- 但我找不到同时指定两者的方法。我错过了什么?
addView(View v,LayoutParams lp)
和addView(View v,int index)
- 但我找不到同时指定两者的方法。为什么呢?因为有一种方法可以同时实现:addView(View child, int index, ViewGroup.LayoutParams params)
:这里。
final ViewGroup rootFrameLayout = (ViewGroup) activity.getWindow().peekDecorView();
LayoutInflater li = LayoutInflater.from(activity);
progressView = li.inflate(R.layout.progressindicator, null);
rootFrameLayout.addView(progressView);
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="3dp"
android:layout_toRightOf="@+id/progressBar1"
android:maxLines="3"
android:lines="3"
android:background="#88000000"
android:textColor="#ffffff"
android:text="@string/waitingForServer" />
如果您想动态更改布局,可以调用布局中元素的方法。如下所示:
TextView textView = (TextView) progressView.findViewById(R.id.textView1);
textView.setMaxLines(lines);
textView.setLines(lines);
textView.setVisibility(View.VISIBLE);