问题
I need to show Progress circle attached over to the TextView but it should be in such way that it wont resist the user to tap on other screen components. something like this
Any clue?
回答1:
Wrap the textview and a Progress bar widget in an appropriate layout. More on ProgressBar here: http://developer.android.com/reference/android/widget/ProgressBar.html
回答2:
set Outer Layout as Framelayout, inside TextView/EditText and ProgressBar set
(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>
回答3:
I have done something like this but it includes an icon as well. Here’s a ready baked code for those who are looking for this.
In your layout use
<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>
This is a linearlayout which contains the textview (an additional icon in front just for kicks) and a small-sized spinning progressbar.
In the activity/fragment add
LinearLayout llMyElement;
On the corresponding onCreate/onCreateView use
llMyElement = (LinearLayout) view.findViewById(R.id.my_element);
On the AsyncTask’s onPostExecute or wherever you want to set the text after a process call setLoadingText(llMyElement, “Some Result");
And include this helper function that sets the text into your Activity class or anywhere suitable such as a Util class.
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);
}
}
And that’s it.. Enjoy!!
回答4:
Put them inside a 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>
This way the ProgressBar
appears over the TextView
. Surely you can hide the ProgressBar whenever you want by setVisibility()
. You can also set each layout's gravity by android:layout_gravity
. In the example above it looks like this:
回答5:
Such a thing is not possible with just a TextView IMO. I guess the best way to mimick such an effect would be to have a LinearLayout with Textview and an Imageview (horizontal orientation). Have the imageview invisible initially. Toggle the visibility of the imageview conditionally. That is, when the action starts, set the visibility and when the action is over,hide it back again.Hope you get the idea.
来源:https://stackoverflow.com/questions/6748118/show-progress-dialog-attached-over-to-textview