1 回答

TA贡献1951条经验 获得超3个赞
我从您的问题中了解到,当您的用户点击pause按钮时,您应该隐藏pause按钮并显示play按钮,反之亦然。这实现起来比较简单。只需创建一个带有两个按钮的线性布局的布局,如下所示:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_horizontal"
android:padding="5dp">
<Button
android:id="@+id/btnPlay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_marginBottom="2dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="2dp"
android:layout_weight="1"
android:text="Play"
android:padding="5dp"/>
<Button
android:id="@+id/btnPause"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginBottom="2dp"
android:layout_marginTop="2dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:text="Pause"/>
</LinearLayout>
现在将单击侦听器设置为两个按钮并在其中处理按钮可见性,如下所示:
Button btnPlay = barcodeDialog.findViewById(R.id.btnPlay);
Button btnPause = barcodeDialog.findViewById(R.id.btnPause);
btnPlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
btnPlay.setVisibility(View.GONE);
btnPause.setVisibility(View.VISIBLE);
}
});
btnPause.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
btnPlay.setVisibility(View.VISIBLE);
btnPause.setVisibility(View.GONE);
}
});
这样您就可以处理您的Play和Pause按钮的可见性。如果您需要更多信息,请回复。
添加回答
举报