我有一些"卡片",这是一个带有TextView的简单LinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/card_label_txt"
android:layout_width="wrap_content"
android:text="label" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
然后我的主片段有一个垂直的LinearLayout ..在这个主片段中我将这个"卡片"添加到主布局:
# main fragment layout
View view = inflater.inflate(R.layout.main_activity, null);
LinearLayout ll = (LinearLayout) view
.findViewById(R.id.main_activity_ll);
# get card
View card = inflater.inflate(R.layout.card, null);
# add to fragment layout
ll.addView(card);
Run Code Online (Sandbox Code Playgroud)
这非常好用我的卡填充片段布局的整个宽度.实际上我在期待什么.
现在我为我的卡创建了一个单独的类:
Class Card extends LinearLayout{
public Card(Context context) {
super(context);
View view = LayoutInflater.from(getContext()).inflate(
R.layout.card, null);
this.addView(view);
}
}
Run Code Online (Sandbox Code Playgroud)
然后,如果我将卡添加到主片段布局中:
# main fragment layout
View view = inflater.inflate(R.layout.main_activity, null);
LinearLayout ll = (LinearLayout) view
.findViewById(R.id.main_activity_ll); …Run Code Online (Sandbox Code Playgroud) android android-context android-layout android-linearlayout android-fragments
我已经实现了导航抽屉,我想在导航抽屉关闭之前加载我的片段.目前,片段与抽屉关闭并行加载,因此如果片段很重,则用户界面会挂起一点.
我的代码是:
private class DrawerItemClickListener implements
ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.content_frame, fragmentProfile);
ft.commit();
drawerLayout.closeDrawer(drawerNaviListView);
}
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能改变这一点,以便首先看到我的片段加载(在后台),当它完成加载时,导航抽屉会关闭?
在我的angular2应用程序中,我向API发送了HTTPS发布请求:
this.http.post('https://myhost.com/api/users/sign_in', body, { headers: contentHeaders })
.subscribe(
response => {.....
Run Code Online (Sandbox Code Playgroud)
我得到"无法加载资源:net :: ERR_INSECURE_RESPONSE"
一切都很好,HTTP直到我切换到HTTPS.
我正在为myhost.com使用自签名证书.
在浏览器中,我能够接受证书并向API发出请求.我可以通过http.postangular2直接解决这个问题吗?
我正在寻找一种在领域查询中组合 AND 和 OR 的方法。
这是我的课:
class Event extends RealmObject {
String id;
String date;
}
Run Code Online (Sandbox Code Playgroud)
现在,我有一个 s 列表id,我想检索Eventid 为 {1, 4, 5} 和 的 s date = "2016-01-01"。在 SQL 中我会有这样的查询:WHERE id IN ids AND date = 'mydate'
到目前为止我尝试过的:
RealmQuery<Event> query = realm.where(Event.class);
for(String id : ids) {
query = query.or().equalTo("id", id);
}
query.equalTo("date", "2016-01-01");
Run Code Online (Sandbox Code Playgroud)
但这样是行不通的。我怎样才能在 Realm 中做到这一点?
如果我在我的 android 设备上安装并运行一个签名的 APK,我会收到这个错误。如果我只是编译一个应用程序并直接在设备上运行,则不会出现此错误。
似乎缺少的片段在我的项目代码中,而不是在任何外部库中。
我如何调查该错误?我试图重建,清理项目等。如果在那里创建了缺少的类,我能以某种方式在 APK 中找到吗?
hier 是错误消息:
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity
ComponentInfo{qua.com.bix/qua.com.bix.main.MainActivity}:
android.support.v4.app.q: Unable to instantiate fragment
qua.com.bix.main.MainLoadingFragment:
make sure class name exists, is public, and has an empty constructor that is public at Android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
....
....
Caused by: android.support.v4.app.q: Unable to instantiate fragment qua.com.bix.main.MainLoadingFragment: make sure class name exists, is public, and has an empty constructor that is public
....
....
Caused by: java.lang.ClassNotFoundException: Didn't find class "qua.com.bix.main.MainLoadingFragment" on path: /data/app/qua.com.bix-1.apk …Run Code Online (Sandbox Code Playgroud) 我正在尝试实现hiera合并.希尔是我的hiera.yaml
---
:hierarchy:
- fqdn/%{fqdn}
- roles/%{role}
- os/%{osfamily}
- common
:backends:
- yaml
# options are native, deep, deeper
:merge_behavior: deeper
:yaml:
:datadir: /etc/puppet/environments/%{environment}/data
Run Code Online (Sandbox Code Playgroud)
然后我有:common.yaml
---
classes:
- a
- b
Run Code Online (Sandbox Code Playgroud)
和fqdn/some.host.yaml
---
classes:
- c
- d
Run Code Online (Sandbox Code Playgroud)
赛跑
hiera --debug -c /etc/puppet/hiera.yaml classes fqdn=some.host environment=development
["c", "d"]
Run Code Online (Sandbox Code Playgroud)
和
hiera --debug -c /etc/puppet/hiera.yaml classes fqdn=blablahost environment=development
["a", "b"]
Run Code Online (Sandbox Code Playgroud)
所以"blablahost"采取common.yaml并应用"a"和"b"类..但是fqdn = some.host应该应用a,b,c,d ..而不仅仅是c,d ...什么是我做错了?
问候
我面临的问题是我在SlidingTabLayout中有一种填充.
这是截图

如你所见,背景来自底部的滑块.最近,使用pagertabstrip库,我没有看到,但现在我尝试了新的com.example.android.common.view.SlidingTabLayout它肯定在那里.如何删除这个填充?
谢谢
和hiere是xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.example.android.common.view.SlidingTabLayout
android:id="@+id/lib_tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/holo_green_light"
/>
<android.support.v4.view.ViewPager
android:id="@+id/lib_pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
样式
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="windowActionBar">false</item>
<item name="colorPrimary">@color/my_action_bar_color</item>
</style>
<style name="ToolBarStyle" parent="">
<item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
<item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>
Run Code Online (Sandbox Code Playgroud)
分段
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.lib_tabs, null);
mViewPager = (ViewPager) view.findViewById(R.id.lib_pager);
mViewPager.setAdapter(new CustomPagerAdapter(this.getFragmentManager()));
mSlidingTabLayout = (SlidingTabLayout) view.findViewById(R.id.lib_tabs); …Run Code Online (Sandbox Code Playgroud) 我有一个卡片视图类,看起来像:
public class CardTest extends LinearLayout {
public CardTest(Context context) {
super(context);
LayoutInflater.from(getContext()).inflate(R.layout.card_main, this);
}
}
Run Code Online (Sandbox Code Playgroud)
card_main.xml如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical"
>
<android.support.v7.widget.CardView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
card_view:cardCornerRadius="4dp">
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Moscow"/>
</android.support.v7.widget.CardView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
然后,如果我在我的片段中
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.view_vll_scrollbar, null);
LinearLayout ll = (LinearLayout) view.findViewById(R.id.vll);
ll.addView(new CardTest(this.getActivity()));
return view;
}
Run Code Online (Sandbox Code Playgroud)
我会看到这个结果(实际上,正如我所料):

但是如果我现在使用带有此代码的RecyclerView
public class CalendarAdapter extends RecyclerView.Adapter<CalendarViewHolder> {
private List<ItemCalendar> mList;
public CalendarAdapter(List<ItemCalendar> list) {
this.mList = list; …Run Code Online (Sandbox Code Playgroud) 我想在数组及其索引中找到相等的值(如果它们连续出现两次以上)。
[0, 3, 0, 1, 0, 1, 2, 1, 2, 2, 2, 2, 1, 3, 4]
Run Code Online (Sandbox Code Playgroud)
所以在这个例子中,我会发现值“2”从位置“8”开始出现“4”次。有没有内置函数可以做到这一点?
我找到了一种方法collections.Counter
collections.Counter(a)
# Counter({0: 3, 1: 4, 3: 2, 5: 1, 4: 1})
Run Code Online (Sandbox Code Playgroud)
但这不是我要找的。当然,我可以编写一个循环并比较两个值,然后对它们进行计数,但可能有更优雅的解决方案吗?