0

我正在尝试在我的活动中包含 Caldroid 日历。我希望日历占据屏幕的 3/4,如下所示:

在此处输入图像描述

但它始终显示在屏幕顶部。

这是我的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/opciones"
        android:layout_width="299dp"
        android:layout_height="match_parent"
        android:orientation="horizontal">
    </LinearLayout>

    <LinearLayout
        android:id="@+id/calendar1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">
    </LinearLayout>

</LinearLayout>

这就是我连接 caldroid 的方式:

  FragmentTransaction t = getSupportFragmentManager().beginTransaction();
        t.replace(R.id.calendar1, caldroidFragment);
        t.commit();

我在 StackOverFlow 中搜索它,但我没有找到解决方案。

4

2 回答 2

0

最后我解决了它实现我自己的 custom_cell 并修改 padding_bottom 以增加单元格大小。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/custom_cell"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="10dp" >

    <TextView
        android:id="@+id/tv1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="68dp"/>

</LinearLayout>

这是一种解决方案,但可能不是最优雅的。

于 2016-12-27T15:24:06.430 回答
-1

有两种方法:

第一种方法: 使用android:layout_weight=""静态大小代替LinearLayout

例如 :

        <LinearLayout
            android:id="@+id/parentLinearLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:id="@+id/options"
                android:layout_width="0dp"
                android:layout_weight="0.3"
                android:layout_height="match_parent"
                android:orientation="horizontal">
            </LinearLayout>

            <LinearLayout
                android:id="@+id/calendar1"
                android:layout_width="0dp"
                android:layout_weight="0.7"
                android:layout_height="match_parent"
                android:orientation="horizontal">
            </LinearLayout>

        </LinearLayout>

第二种方式: 使用PercentLayout(使用百分比,也许更清晰)

  1. Percent通过将此行添加到 gradle 依赖项,将库添加到您的应用程序:

     dependencies {
    ...
    compile 'com.android.support:percent:24.1.2' //or any other versions
    ...
    }
    
  2. XML layout

        <LinearLayout
            android:id="@+id/options"
            android:layout_width="0dp"
            app:layout_widthPercent="30%"
            android:layout_height="match_parent"
            android:orientation="horizontal">
        </LinearLayout>
    
        <LinearLayout
            android:layout_toRightOf="@id/options"
            android:id="@+id/calendar1"
            android:layout_width="0dp"
            app:layout_widthPercent="70%"
            android:layout_height="match_parent"
            android:orientation="horizontal">
    </LinearLayout>
    

请注意:

  • 添加http://schemas.android.com/apk/res-auto"到布局的第一个父级
  • android:layout_toRightOf指定第二个视图(layout_below也可以)
于 2016-12-26T18:40:46.723 回答