Mic*_*rne 8 android android-ui android-animation
我的应用程序上有一个很大的"登录"按钮.当用户点击此按钮时,我想用"登录..."替换文本,将其对齐到左边而不是中心,并在右边放一个旋转的圆圈(但仍然在按钮内).我想在我的应用程序的其他地方使用基本相同的按钮(但具有不同的初始和加载文本).
最好的方法是什么?对于实际的旋转图形,我计划使用@drawable/spinner_white_16Android附带的.
谢谢.
Dav*_*ave 10
您可以使用包含TextView和ImageView的RelativeLayout创建自己的按钮.
<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>
Run Code Online (Sandbox Code Playgroud)
然后,无论您调用哪种登录方法,都要更改TextView的内容,使其右对齐,并将ImageView可见性设置为可见.
loginText.setText("Logging In...");
LayoutParams params = loginText.getLayoutParams();
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
loginText.setLayoutParams(params);
loginLoading.setVisibility(View.VISIBLE);
Run Code Online (Sandbox Code Playgroud)
然后我还会有一些代码可以在登录失败时撤消这些更改.
这是我想出的一个实现,希望它可以重用:
此时,当用户单击该按钮时,它将为您显示可绘制(和动画),但是您必须在完成后台任务后手动关闭加载动画:
_progressButton.stopLoadingAnimation();
Run Code Online (Sandbox Code Playgroud)
这将为您解除任何动画并显示之前的任何文本.唯一缺少它的是动画正在进行中没有文字,但我认为你可以一起破解一些东西.我计划进一步扩展它,以便它可以调用类似的东西_progressButton.setProgress(10),然后设置完成的百分比.我甚至可以让它安全线程.
这样您就不必使用多个布局并在按钮顶部嵌入任何文本视图,而且所有这些都是为您处理的.
| 归档时间: |
|
| 查看次数: |
14530 次 |
| 最近记录: |