小编ada*_*000的帖子

使用工具栏+ TabLayout充气AppBarLayout

我目前在main.xml中有一个DrawerLayout.有一个工具栏包装在AppBarLayout中,然后是一个简单的LinearLayout来交换片段.

我导航到的一个片段,我希望它包含一个用于ViewPager片段的TabLayout.目前,我在片段的布局文件中都有这两个,但这会导致工具栏和TabLayout之间出现阴影,这是我不想要的.我也不想使用setElevation(),因为它不适用于pre-Lollipop设备.

一个可能的解决方案是从我的片段中膨胀AppBarLayout,以便它同时包含工具栏+标签.但是,我不确定如何做到这一点,所以任何帮助将不胜感激.

这是我的main.xml文件:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.lumivote.lumivote.ui.MainActivity">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/rootLayout"
        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.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

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

        <LinearLayout
            android:id="@+id/flContent"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

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

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/nav_header"
        app:itemIconTint="#333"
        app:itemTextColor="#333"
        app:menu="@menu/navigation_drawer_items" />

</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)

这是我的片段的xml文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.alexdao.democracy.ui.candidate_tab.CandidateListFragment">

    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/myPrimaryColor"
        app:tabMode="fixed"
        app:tabGravity="fill"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

android android-layout android-fragments android-toolbar android-tablayout

24
推荐指数
3
解决办法
9665
查看次数

Android包组织

我是Android开发的新手,所以我对Android项目/代码设计有一些疑问.

  1. 人们通常会将API调用分成单独的类/类吗?或者你在对象本身内调用它们?
  2. 包只是子目录吗?据我所知,它们仅用于程序员作为组织工具的利益.

我知道这些问题有些主观,但我对其他开发人员如何组织代码感兴趣.谢谢!

java android

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

使用GVM安装Groovy

当我尝试运行此命令以使用GVM安装Groovy时,我收到以下错误消息:

$gvm install groovy
Stop! groovy is not a valid candidate.
Run Code Online (Sandbox Code Playgroud)

为什么这不起作用?据我所知,我使用这个正确安装了GVM:

$ curl -s get.gvmtool.net | bash
Run Code Online (Sandbox Code Playgroud)

我在Mac上

这是我跑步时看到的gvm help:

$ gvm help

Usage: gvm <command> <candidate> [version]
       gvm offline <enable|disable>

   commands:
       install   or i    <candidate> [version]
       uninstall or rm   <candidate> <version>
       list      or ls   <candidate>
       use       or u    <candidate> [version]
       default   or d    <candidate> [version]
       current   or c    [candidate]
       outdated  or o    [candidate]
       version   or v
       broadcast or b
       help      or h
       offline           <enable|disable>
       selfupdate        [force] …
Run Code Online (Sandbox Code Playgroud)

groovy gvm

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

使用 bfs 的拓扑顺序

在 Sedgewick 和 Wayne 关于 java 算法的书中发现了以下问题:

4.2.19 拓扑排序和 BFS。解释为什么以下算法不一定会产生拓扑顺序:运行 BFS,并通过增加与各自源的距离来标记顶点。

我试图证明它找到一个反例。但是,每次我尝试时,都会得到一个拓扑顺序。我的意思是,我不明白为什么这不起作用:如果顶点的源在它之前,为什么我们没有拓扑顺序?

我想为了证明它,我们需要找到一个它的来源之前出现的顶点,但我不能。

有人有反例吗?提前致谢!

PS:这不是作业

@Edit:我尝试过像 1 <- 2 <- 0 <- 3 <- 4 这样的汉密尔顿路径,它给出 0 3 4 2 1,但是改变 0 3 和 4 的位置给了我一个拓扑顺序(但是,按照我获得的顺序,它不是)。我不确定这是否是拓扑顺序。

algorithm breadth-first-search topological-sort

4
推荐指数
1
解决办法
1909
查看次数