小编cur*_*guy的帖子

自动隐藏android中的媒体播放器布局

我正在设计一个自定义布局的媒体播放器.我希望界面在16秒不活动后消失.如果用户触摸屏幕,它应该重新出现.代码段如下:

 public void showhideControllers(int n) {
    if (n == 1) {
        /* make layout invisible */

        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            public void run() {
                volumeBar.setVisibility(View.INVISIBLE);
                audioControllView.setVisibility(View.INVISIBLE);
                topBar.setVisibility(View.INVISIBLE);
            }
        }, 16000);

    } else {
        /* make layout visible */           
        volumeBar.setVisibility(View.VISIBLE);
        topBar.setVisibility(View.VISIBLE);
        audioControllView.setVisibility(View.VISIBLE);

        showhideControllers(1);
    }

}

    @Override
public void onUserInteraction() {
    super.onUserInteraction();
    showhideControllers(2);
}
Run Code Online (Sandbox Code Playgroud)

在onCreate()中,我通过调用showhideControllers(1);来启动计时器.现在,当我点击屏幕时,布局重新出现并重置计时器.但是,如果我随机点击屏幕,则每次点击后计时器都不会重置,并且布局会在16秒后消失.你能告诉我我做错了什么吗?

android android-layout

9
推荐指数
1
解决办法
848
查看次数

布局用不同的颜色

我想要的背景颜色RelativeLayout与下面链接中显示的图像类似.忽略图像下半部分的黑条.

图片1

我不想将图像用作布局的背景.你能告诉我如何继续吗?

android android-layout

9
推荐指数
2
解决办法
1722
查看次数

单击时更改小部件可见性

我的小部件包含两个相对布局.我已经使两个布局都可以点击了.以下是布局的ID:

android:id="@+id/upper_layout" 
android:id="@+id/bottom_layout"
Run Code Online (Sandbox Code Playgroud)

现在,我需要的是,如果用户点击upper_layout,则bottom_layout应该是不可见的.

在这里,我到目前为止尝试过,但它不起作用.你能检查一下我做错了什么吗?或者,也许建议一些其他方法来实现这一目标.

代码:

public class BobsWidget extends AppWidgetProvider {

    public static String ACTION_WIDGET_RECEIVER = "Clicked";

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,
            int[] appWidgetIds) {

        RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
                R.layout.main);
        Intent active = new Intent(context, BobsWidget.class);
        active.setAction(ACTION_WIDGET_RECEIVER);

        PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context,
                0, active, 0);

        remoteViews.setOnClickPendingIntent(R.id.upper_layout,
                actionPendingIntent);

        appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);

    }

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        // check, if our Action was called
        if (intent.getAction().equals(ACTION_WIDGET_RECEIVER)) {
            RemoteViews remoteViews = new …
Run Code Online (Sandbox Code Playgroud)

android android-widget android-intent android-layout

7
推荐指数
1
解决办法
1754
查看次数