RelativeLayout子项内的水平滚动

时间:2015-02-01 16:20:12

标签: android

我希望有一个代表月日的方形矩形,我已经编写了这个布局:

item_single_basi.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="1dp">

    <LinearLayout
        android:id="@+id/LinearLayout0"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <TextView
            android:layout_width="@dimen/size_single_item"
            android:layout_height="@dimen/size_single_item"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="99"
            android:tag="txtdata"
            android:id="@+id/txtdata"
            android:padding="2dp"
            android:layout_margin="1dp"
            android:gravity="center"
            android:textStyle="bold" />

        <TextView
            android:layout_width="@dimen/size_single_item"
            android:layout_height="@dimen/size_single_item"
            android:text="99"
            android:tag="txtbase1"
            android:id="@+id/txtbase1"
            android:layout_below="@+id/txtdata"
            android:background="@drawable/black_border_white_background"
            android:padding="2dp"
            android:layout_margin="1dp"
            android:gravity="center" />
        <TextView
            android:layout_width="@dimen/size_single_item"
            android:layout_height="@dimen/size_single_item"
            android:text="99"
            android:tag="txtbase2"
            android:id="@+id/txtbase2"
            android:layout_below="@+id/txtbase1"
            android:padding="2dp"
            android:background="@drawable/black_border_yellow_background"
            android:layout_margin="1dp"
            android:gravity="center" />
        <TextView
            android:layout_width="@dimen/size_single_item"
            android:layout_height="@dimen/size_single_item"
            android:text="99"
            android:tag="txtbase3"
            android:id="@+id/txtbase3"
            android:layout_below="@+id/txtbase2"
            android:background="@drawable/black_border_brown_background"
            android:padding="2dp"
            android:layout_margin="1dp"
            android:gravity="center" />
    </LinearLayout>
</RelativeLayout>

这些日子是在一个月内组装的:

mese_basi.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:scrollbarStyle="insideOverlay"
    android:scrollbars="vertical" >


    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data1"
        android:tag="1"
        android:layout_alignParentTop="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </com.bandweb.mycpstore.Basi_Column>

    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data2"
        android:tag="2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data1"
        android:layout_toEndOf="@+id/data1">
    </com.bandweb.mycpstore.Basi_Column>

    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data3"
        android:tag="3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data2"
        android:layout_toEndOf="@+id/data2">
    </com.bandweb.mycpstore.Basi_Column>
    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data4"
        android:tag="4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data3"
        android:layout_toEndOf="@+id/data3">
    </com.bandweb.mycpstore.Basi_Column>
    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data5"
        android:tag="5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data4"
        android:layout_toEndOf="@+id/data4">
    </com.bandweb.mycpstore.Basi_Column>
    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data6"
        android:tag="6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data5"
        android:layout_toEndOf="@+id/data5">
    </com.bandweb.mycpstore.Basi_Column>
    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data7"
        android:tag="7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data6"
        android:layout_toEndOf="@+id/data6">
    </com.bandweb.mycpstore.Basi_Column>
    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data8"
        android:tag="8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data7"
        android:layout_toEndOf="@+id/data7">
    </com.bandweb.mycpstore.Basi_Column>
    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data9"
        android:tag="9"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data8"
        android:layout_toEndOf="@+id/data8">
    </com.bandweb.mycpstore.Basi_Column>
    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data10"
        android:tag="10"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data9"
        android:layout_toEndOf="@+id/data9">
    </com.bandweb.mycpstore.Basi_Column>

    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data11"
        android:tag="11"
        android:layout_alignParentTop="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/data10"
        android:layout_toEndOf="@+id/data10">
    </com.bandweb.mycpstore.Basi_Column>

    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data12"
        android:tag="12"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data11"
        android:layout_toEndOf="@+id/data11">
    </com.bandweb.mycpstore.Basi_Column>

    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data13"
        android:tag="13"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data12"
        android:layout_toEndOf="@+id/data12">
    </com.bandweb.mycpstore.Basi_Column>
    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data14"
        android:tag="14"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data13"
        android:layout_toEndOf="@+id/data13">
    </com.bandweb.mycpstore.Basi_Column>
    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data15"
        android:tag="15"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data14"
        android:layout_toEndOf="@+id/data14">
    </com.bandweb.mycpstore.Basi_Column>
    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data16"
        android:tag="16"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data15"
        android:layout_toEndOf="@+id/data15">
    </com.bandweb.mycpstore.Basi_Column>
    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data17"
        android:tag="17"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data16"
        android:layout_toEndOf="@+id/data16">
    </com.bandweb.mycpstore.Basi_Column>
    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data18"
        android:tag="18"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data17"
        android:layout_toEndOf="@+id/data17">
    </com.bandweb.mycpstore.Basi_Column>
    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data19"
        android:tag="19"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data18"
        android:layout_toEndOf="@+id/data18">
    </com.bandweb.mycpstore.Basi_Column>
    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data20"
        android:tag="20"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data19"
        android:layout_toEndOf="@+id/data19">
    </com.bandweb.mycpstore.Basi_Column>

    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data21"
        android:tag="21"
        android:layout_alignParentTop="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/data20"
        android:layout_toEndOf="@+id/data20">
    </com.bandweb.mycpstore.Basi_Column>

    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data22"
        android:tag="22"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data21"
        android:layout_toEndOf="@+id/data21">
    </com.bandweb.mycpstore.Basi_Column>

    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data23"
        android:tag="23"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data22"
        android:layout_toEndOf="@+id/data22">
    </com.bandweb.mycpstore.Basi_Column>
    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data24"
        android:tag="24"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data23"
        android:layout_toEndOf="@+id/data23">
    </com.bandweb.mycpstore.Basi_Column>
    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data25"
        android:tag="25"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data24"
        android:layout_toEndOf="@+id/data24">
    </com.bandweb.mycpstore.Basi_Column>
    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data26"
        android:tag="26"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data25"
        android:layout_toEndOf="@+id/data25">
    </com.bandweb.mycpstore.Basi_Column>
    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data27"
        android:tag="27"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data26"
        android:layout_toEndOf="@+id/data26">
    </com.bandweb.mycpstore.Basi_Column>
    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data28"
        android:tag="28"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data27"
        android:layout_toEndOf="@+id/data27">
    </com.bandweb.mycpstore.Basi_Column>
    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data29"
        android:tag="29"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data28"
        android:layout_toEndOf="@+id/data28">
    </com.bandweb.mycpstore.Basi_Column>
    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data30"
        android:tag="30"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/data29"
        android:layout_toEndOf="@+id/data29">
    </com.bandweb.mycpstore.Basi_Column>

    <com.bandweb.mycpstore.Basi_Column
        android:id="@+id/data31"
        android:tag="31"
        android:layout_alignParentTop="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/data30"
        android:layout_toEndOf="@+id/data30">
    </com.bandweb.mycpstore.Basi_Column>


</RelativeLayout>

最后这个月与其他控件组合在一起:

mese_completo.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Medium Text"
            android:id="@+id/txt_nome_mese"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignRight="@+id/Gennaio"
            android:layout_alignEnd="@+id/Gennaio"
            android:paddingLeft="10dp" />

        <com.bandweb.mycpstore.Basi_Column
            android:id="@+id/Legenda"
            android:tag="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/txt_nome_mese"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginRight="5dp">
        </com.bandweb.mycpstore.Basi_Column>

        <com.bandweb.mycpstore.Basi_Mese
            android:id="@+id/Mese"
            android:tag="2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/txt_nome_mese"
            android:layout_toRightOf="@+id/Legenda"
            android:layout_toEndOf="@+id/Legenda">
        </com.bandweb.mycpstore.Basi_Mese>

        <com.bandweb.mycpstore.Basi_Column
            android:id="@+id/totale1"
            android:tag="3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/txt_nome_mese"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true">
        </com.bandweb.mycpstore.Basi_Column>

</RelativeLayout>

问题是我希望有一个30dp和31天的方形矩形来匹配以表示一行。 是否可以使用滚动条滚动当天? 对我来说,如果只有mounth卷轴的那一天,那将是最好的,而 Legenda totale1 仍然是 alignParentLeft alignParentRight 。 有可能吗?

enter image description here

编辑解决了!

<HorizontalScrollView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/txt_nome_mese"
            android:layout_toRightOf="@+id/Legenda"
            android:layout_toLeftOf="@+id/totale1"
            android:layout_toStartOf="@+id/totale1">
                <com.bandweb.mycpstore.Basi_Mese
                    android:id="@+id/Mese"
                    android:tag="2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    >
                </com.bandweb.mycpstore.Basi_Mese>
        </HorizontalScrollView>

1 个答案:

答案 0 :(得分:1)