gpt4 book ai didi

Android - 按下时带有旋转/旋转 'loading' 图像的按钮

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:52:39 28 4
gpt4 key购买 nike

我的应用程序上有一个很大的“登录”按钮。当用户点击此按钮时,我想用“正在登录...”替换文本,将其对齐到左侧而不是中心,并在右侧放置一个旋转的圆圈(但仍在按钮内)。我想在我的应用程序的其他地方使用基本相同的按钮(但具有不同的初始和加载文本)。

执行此操作的最巧妙方法是什么?对于实际的旋转图形,我打算使用 Android 自带的 @drawable/spinner_white_16

谢谢。

最佳答案

您可以使用包含 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>

然后在调用任何登录方法时,更改 TextView 的内容,使其与父级右对齐,并将 ImageView 可见性设置为可见。

loginText.setText("Logging In...");
LayoutParams params = loginText.getLayoutParams();
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
loginText.setLayoutParams(params);
loginLoading.setVisibility(View.VISIBLE);

然后我还会有一些代码可以在登录失败时撤消这些更改。

关于Android - 按下时带有旋转/旋转 'loading' 图像的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13269546/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com