Android的 - 按键采用旋转/旋转“正在加载”的形象时,pressed [英] Android - Button with rotating/spinning 'loading' image when pressed
问题描述
我有一个很大的登录按钮,在我的应用程序。当用户点击这个按钮,我要替换文本正在登录...,对齐到左边,而不是中心,把右侧的旋转一圈(但仍按钮内)。我想基本上使用相同的按钮(但具有不同的初始和加载文本)在其他地方在我的应用程序。
I have a big 'Log in' button on my app. When the user taps this button, I want to replace the text with 'Logging in...', align it to the left instead of center and put a spinning circle on the right (but still inside the button). I'd like to use essentially the same button (but with different initial and loading text) in other places in my app.
什么是做到这一点的最巧妙的方法?对于实际纺纱图形,我正打算使用 @绘制/ spinner_white_16
自带的Android系统。
What's the neatest way to do this? For the actual spinning graphic, I was planning to use the @drawable/spinner_white_16
that comes with Android.
感谢。
推荐答案
您可以使用包含一个TextView和ImageView的一个RelativeLayout的创建自己的按钮。
You can create your own button using a RelativeLayout containing a TextView and an ImageView.
<RelativeLayout android:id="@+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
onClick="[yourLoginMethod]" >
<TextView android:id="@+id/login_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Log In" />
<ImageView android:id="@+id/login_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/login_text"
android:visibility="gone" />
</RelativeLayout>
然后在任何您的登录方法被调用,改变TextView的内容,使其对准父母的权利,并设置ImageView的知名度可见。
And then in whatever your login method is called, change the contents of the TextView, make it align parent right, and set the ImageView visibility to visible.
loginText.setText("Logging In...");
LayoutParams params = loginText.getLayoutParams();
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
loginText.setLayoutParams(params);
loginLoading.setVisibility(View.VISIBLE);
然后,我也有一些code可逆转的变化,如果登录失败。
And then I would also have some code that reverses those changes if the login fails.
这篇关于Android的 - 按键采用旋转/旋转“正在加载”的形象时,pressed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!