小编ssc*_*mid的帖子

使用AppBarLayout的Android SupportLib - FrameLayout中的FrameLayout消耗整个屏幕高度

我目前FrameLayoutCoordinatorLayoutAndroid设计支持库中遇到问题,而我在创建选项卡时遵循了这篇文章中的说明.

基本上大多数事情按预期工作,容器碎片被充气到FrameLayout他们的标签 - 片段被相关地添加到ViewPageras标签(需要它这样,因为我有许多片段,应该重用布局).

我挣扎的问题是,在FrameLayout(并且结果也制表片段)消耗整个屏幕高度,使其重叠的ToolbarTabLayout.为了可视化问题,我创建了以下图像:

可视化问题

基本布局与CoordinatorLayout,ToolbarTabLayout:

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <include layout="@layout/toolbar" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </android.support.design.widget.AppBarLayout>

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

片段使用的单独布局膨胀为container:

<android.support.v4.view.ViewPager
    android:id="@+id/viewPager"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />
Run Code Online (Sandbox Code Playgroud)

所有片段都被我的BaseFragment类夸大了(在SO调用的另一个帖子上inflater.inflate(getLayoutRes(), null);引发同样问题的问题)

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    return inflater.inflate(getLayoutRes(), container, false); …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-fragments android-support-design

27
推荐指数
1
解决办法
9524
查看次数

当android设备连接到WIFI时,不要收到GCM消息

背景

我正在开发一款Android应用,它使用Google Cloud Messaging(新的GCM-API,而不是已弃用的C2DM)向所有已注册的设备发送发送至同步消息.

由于我使用的是官方文档,因此我的客户端实现与Google的示例几乎完全相同.作为服务器,我使用在localhost上运行的简单PHP脚本,其唯一任务是向GCM发送发送到同步消息.

问题

只要我的设备通过UMTS等蜂窝网络连接到互联网,一切正常(服务器向GCM发送通知> GCM一旦联机就将通知推送到设备>设备上显示通知).

但是当设备连接到WIFI时,将不再接收GCM消息(尽管Google会向我的PHP服务器发送"成功"信息).由于以下答案,我已经检查过我的路由器是否阻止某些端口,但它没有.

我有同样的接收推送消息的问题,即使GCM服务器回复"成功",因为wifi隐私.当我使用我的公司wifi时,我不能在移动设备上接收消息,因为它们被阻止了GCM服务器端口.

有趣的是,我的实施已经与WIFI一起工作......

Google从PHP发送GCM消息时的回复:

{
    "multicast_id":4677038582377051331,
    "success":1,
    "failure":0,
    "canonical_ids":0,
    "results":[{"message_id":"0:1406364179145476%6ce83c64d7d6c7e2"}]
}
Run Code Online (Sandbox Code Playgroud)


非常疯狂的发现:

当我调用PHP脚本从智能手机发送我的GCM消息时,问题就解决了,因为一切正常.

暗示

同时,这个"新"GCM-API也被弃用了!我现在正在使用最新的GCM-API(2015年夏季发布).自升级以来,我再也没遇到过这个问题.从我的观点来看,新的API,包括InstanceId-API是非常值得推荐的,据我所知,它比旧的GCM更稳定.

android wlan google-cloud-messaging

6
推荐指数
1
解决办法
8052
查看次数

带有ListView的Android Widget仅显示加载视图

我正在尝试使用ListView实现Android App Widget.我开始关注Google文档但是我遇到了正在显示的加载视图列表,而不是正常的列表项.有没有人有小部件列表视图的经验?

代码与Google文档中的代码相同.我使用ListView而不是StackView作为数据源我使用数据库(这不是问题,数据是正确获得的 - 我通过返回正常的列表项视图而不是默认的加载视图尝试了这一点)

搜索互联网没有帮助我...我也试过这个教程,但它也没有用.我希望有人可以帮助我,提前谢谢!

WidgetProvider.java

public class WidgetProvider extends AppWidgetProvider {

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

        for (int i = 0; i < appWidgetIds.length; i++) {

            Intent intent = new Intent(context, EventWidgetService.class);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
            intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));

            RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget);
            rv.setRemoteAdapter(android.R.id.list, intent);
            rv.setEmptyView(android.R.id.list, R.id.tvEmptyList);

            appWidgetManager.updateAppWidget(appWidgetIds[i], rv);
        }

        super.onUpdate(context, appWidgetManager, appWidgetIds);
    }
}
Run Code Online (Sandbox Code Playgroud)

WidgetService.java

public class EventWidgetService extends RemoteViewsService {

    @Override …
Run Code Online (Sandbox Code Playgroud)

android android-listview remoteview android-appwidget

5
推荐指数
1
解决办法
2448
查看次数