我想在一个使用TabLayout的Activity中实现一个ListFragment,这样我就可以在不同的列表之间滑动.最后它应该成为一个预订应用程序,以便您可以选择不同的学科,并预订一个特定的时间段.然而到目前为止,我只实现了ListActivity或标签活动(android studio中的标准活动),但不是两者.如果有人可以提供帮助,我会很高兴的.标签式活动:
public class Diciplines extends AppCompatActivity {
/**
* The {@link android.support.v4.view.PagerAdapter} that will provide
* fragments for each of the sections. We use a
* {@link FragmentPagerAdapter} derivative, which will keep every
* loaded fragment in memory. If this becomes too memory intensive, it
* may be best to switch to a
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
*/
private SectionsPagerAdapter mSectionsPagerAdapter;
/**
* The {@link ViewPager} that will host the section contents.
*/
private ViewPager mViewPager;
@Override
protected void onCreate(Bundle …Run Code Online (Sandbox Code Playgroud) 在我的活动中,我正在设置布局activity_main onCreate.我想为我的阵列中的每个项目充气我的CardView.
到目前为止,我已经装好了所有东西,但是我的CardView已经失去了它们的余量.通过XML添加到布局时,边距有效,但当它作为单独的XML文件膨胀时,边距会丢失.
我像这样膨胀activity_main_card:
LinearLayout item = (LinearLayout)findViewById(R.id.card_holder);
View child = getLayoutInflater().inflate(R.layout.activity_main_card, null);
item.addView(child);
Run Code Online (Sandbox Code Playgroud)
在activity_main_card中,我的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/card_view"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="2dp"
android:layout_marginBottom="16dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:scaleType="fitCenter"
android:background="@drawable/cin"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="@color/dark_grey"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textStyle="normal"
android:textColor="@color/grey_500"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)
任何人都能指出我出错的方向吗?