停止相对布局中水平重叠的视图

时间:2016-04-28 15:57:41

标签: android views relativelayout

我有两个视图,一个日视图和一个事件视图作为日历的一部分。我希望我的事件以宽度填充日视图(这是有效的)但是当我在相同的位置/时间添加另一个时我希望它们分割宽度...我正在使用java动态添加我的事件。是否有可以使用的属性,以便视图不重叠?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="@+id/dayView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/day_view">

</RelativeLayout>

<?xml version="1.0" encoding="utf-8"?>
<ie.test.calendar.CalendarEventView
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:id="@+id/eventView"
android:background="@drawable/event_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">

    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/eventTextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="3dp"
    android:paddingBottom="5dp"
    android:paddingLeft="5dp"
    android:paddingRight="3dp"
    android:textAppearance="@android:style/TextAppearance.Medium"
    android:textColor="@android:color/white"/>

</ie.test.calendar.CalendarEventView>

2 个答案:

答案 0 :(得分:0)

我认为您需要将Linier布局用作具有水平方向的父视图。并且还使用重量的概念宽度。它将根据子数量

显示您的父视图

答案 1 :(得分:0)

查看RelativeLayout.LayoutParams

您可以使用ID来在运行时设置规则。

layoutparams.addRule(RelativeLayout.ALIGN_RIGHT, R.id.id1)

虽然,我认为使用LinearLayout会更简单。

相关问题