显示附加到textview的进度对话框

时间:2011-07-19 13:43:20

标签: android layout textview loader progressdialog

我需要将Progress圆圈显示在TextView上,但它应该是这样的,它不会让用户无法点击其他屏幕组件。像这样的东西

enter image description here

有任何线索吗?

5 个答案:

答案 0 :(得分:5)

以适当的布局包装textview和Progress bar小部件。有关ProgressBar的更多信息: http://developer.android.com/reference/android/widget/ProgressBar.html

答案 1 :(得分:1)

我做过类似的事情,但它也包含一个图标。这是一个现成的烘焙代码,供那些正在寻找这个的人使用。

在你的布局中使用

<LinearLayout
    android:id="@+id/my_element"
    android:layout_width="match_parent"
    android:layout_marginLeft="20dp"
    android:layout_marginTop="5dp"
    android:layout_height="20dp">

    <ImageView
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:src="@drawable/ic_action_place"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="20dp"
        android:textColor="@color/black"
        android:textSize="12sp"
        android:gravity="center_vertical"
        android:text=""/>

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="20dp"
        style="@android:style/Widget.ProgressBar.Small"
        android:layout_marginRight="5dp" />

</LinearLayout>

这是一个linearlayout,其中包含textview(前面的一个额外图标,仅用于踢腿)和一个小型旋转进度条。

在活动/片段中添加

LinearLayout llMyElement;

在相应的onCreate / onCreateView上使用

llMyElement = (LinearLayout) view.findViewById(R.id.my_element);

在AsyncTask的onPostExecute上或在进程调用setLoadingText(llMyElement, “Some Result");

之后设置文本的位置

并包含此辅助函数,该函数将文本设置为您的Activity类或适合的任何地方,例如Util类。

public void setLoadingText(LinearLayout layout, String text)
{
    int count = layout.getChildCount();
    for(int  i = 0; i < count; i++)
    {
        if(layout.getChildAt(i) instanceof TextView)
            ((TextView) layout.getChildAt(i)).setText(text);
        if(layout.getChildAt(i) instanceof ProgressBar)
            layout.getChildAt(i).setVisibility(View.GONE);
    }
}

就是这样......享受!!

答案 2 :(得分:0)

只有TextView IMO才能实现这样的功能。我想模仿这种效果的最佳方法是使用带有Textview的LinearLayout和Imageview(水平方向)。最初看不见imageview。有条件地切换图像视图的可见性。也就是说,当动作开始时,设置可见性,当动作结束时,再次将其隐藏起来。希望你明白这一点。

答案 3 :(得分:0)

enter image description here将外部布局设置为Framelayout,在TextView / EditText和ProgressBar中设置(layout gravity "Right")

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/TextView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingRight="24dp"
        android:text="Getting Location"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textSize="12dp" >

        <requestFocus />
    </TextView>

    <ProgressBar
        android:id="@+id/ProgressBar01"
        style="?android:attr/progressBarStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right|center_vertical"
        android:layout_marginRight="4dp" />
</FrameLayout>

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="16dp" >

    <EditText
        android:id="@+id/EditText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingRight="24dp"
        android:text="http://example.com"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textSize="12dp" />

    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right|center_vertical"
        android:layout_marginRight="4dp" />
</FrameLayout>

答案 4 :(得分:0)

将它们放在FrameLayout

<FrameLayout
    android:layout_width="0dp"
    android:layout_height="100dp"
    android:layout_weight="1">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/my_info_card"
        android:gravity="center"
        android:layout_gravity="center"/>
    <ProgressBar
        android:id="@+id/progress_bar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@android:style/Widget.ProgressBar.Small"
        android:layout_gravity="center"/>
</FrameLayout>

这样ProgressBar出现在TextView上方。当然,您可以随时通过setVisibility()隐藏ProgressBar。您还可以按android:layout_gravity设置每个布局的重力。在上面的示例中,它看起来像这样:

ProgressBar over TextView