Caldroid:如何修改大小和位置
Caldroid: How to modify size and position
我想在我的 activity 中加入 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();
我在 Whosebug 中搜索它,但没有找到解决方案。
有两种方法:
第一种方式:
使用 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
(使用百分比,也许更清晰)
通过将此行添加到 gradle 依赖项来将 Percent
库添加到您的应用程序:
dependencies {
...
compile 'com.android.support:percent:24.1.2' //or any other versions
...
}
在 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
也可以)
最后我解决了它实现我自己的 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>
这是一种解决方案,但可能不是最优雅的。
我想在我的 activity 中加入 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();
我在 Whosebug 中搜索它,但没有找到解决方案。
有两种方法:
第一种方式:
使用 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
(使用百分比,也许更清晰)
通过将此行添加到 gradle 依赖项来将
Percent
库添加到您的应用程序:dependencies { ... compile 'com.android.support:percent:24.1.2' //or any other versions ... }
在
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
也可以)
最后我解决了它实现我自己的 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>
这是一种解决方案,但可能不是最优雅的。