それぞれの下にタブとフラグメントを表示するためActionBarActivity
に含むがあります。
現在、各タブの下にロードされているフラグメントは ですが、それをカードにしたい (の一部として、このカードに私の を含めます。ビュー内のコンテナーに
を配置できることはわかっていますが、配置することは可能ですか?のコンテナ?HorizontalScrollView
PreferenceFragment
cardView
PreferenceFragment
PreferenceFragment
Activity
Fragment
1899 次
3 に答える
0
フラグメント用にインフレートしたレイアウトは、カードビューでラップできます。
断片
public View onCreateView(...) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.news_card_row, container, false);
return rootView;
}
xml
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/fssr_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</android.support.v7.widget.CardView>
于 2014-11-26T19:42:36.023 に答える
-2
私が見つけた最良の方法は、ネストされたフラグメントを AppCompat で使用することでしたgetChildFragmentManager()
。
カードで作成した Swipe View で機能する私のコードは、あなたのために機能すると思います:
PrefsFragment.java:
public class PrefsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.settings);
}
PrefsContainerFragment.java:
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class PrefsContainerFragment extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fragment prefsFragment = new PrefsFragment();
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.add(R.id.child_fragment, prefsFragment).commit();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_pref, container,false);
}
}
fragment_pref XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
card_view:cardCornerRadius="4dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
card_view:cardBackgroundColor="@color/cardview_light_background"
android:layout_margin="@dimen/card_padding"
tools:context=".PrefFragment"
android:clickable="false">
<FrameLayout
android:id="@+id/child_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v7.widget.CardView>
FragmentTransaction
メソッドのに問題がある可能性がありますが、onCreate
私が知る限り、子 Fragment の も使用addPreferencesFromResource(R.xml.settings);
しているため機能します。onCreate
ただし、うまくいかない場合は、onCreateView
またはに入れてみてくださいonActivityCreated
。
于 2014-12-20T20:22:31.063 に答える