Android布局形状

时间:2015-05-06 19:31:32

标签: android xml layout

是否可以使用XML获取图片的布局。我需要在一个屏幕上并排显示其中两个。

左侧将静态显示,从1到24显示不同的颜色区域,右侧将完全相同但分解为24个,因此我可以通过编程方式操作它们并定义它们出现的顺序。 / p>

我不需要它可滚动,它将在各种设备上使用,因此它必须是灵活的。当前的实现是左边有一个image.jpg,右边是imageView。正确的图片被分成24个jpg并动态插入。

https://dl.dropboxusercontent.com/u/71295596/demo.jpg

原型:https://www.fluidui.com/editor/live/preview/p_q1cf2aIWUbpBTobbPNQ61lF6xJcDG1gn.1430943636421

和我当前的xml文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="511dp"
        android:layout_weight="1"
        android:padding="0dp"
        android:scaleType="fitXY"
        android:src="@mipmap/time24h" />

    <LinearLayout
        android:id="@+id/time_linear_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical"
        android:padding="0dp">

    </LinearLayout>

</LinearLayout>

<View
    android:id="@+id/line"
    android:layout_width="fill_parent"
    android:layout_height="5dp"
    android:background="#0f0" />

我尝试做类似下面的事情,但它没有表现出来。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="2"
    android:orientation="vertical">


    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="9"
        android:layout_weight="1">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/material_blue_grey_800"
            android:text="1"
            android:layout_weight="1"
            android:textColor="@color/md_white_1000"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/material_blue_grey_800"
            android:text="2"
            android:textColor="@color/md_white_1000"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_yellow_100"
            android:textColor="@color/md_white_1000"
            android:text="3"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/material_blue_grey_800"
            android:text="1"
            android:layout_weight="1"
            android:textColor="@color/md_white_1000"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/material_blue_grey_800"
            android:text="2"
            android:textColor="@color/md_white_1000"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_yellow_100"
            android:textColor="@color/md_white_1000"
            android:text="3"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/material_blue_grey_800"
            android:text="1"
            android:layout_weight="1"
            android:textColor="@color/md_white_1000"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/material_blue_grey_800"
            android:text="2"
            android:textColor="@color/md_white_1000"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_yellow_100"
            android:textColor="@color/md_white_1000"
            android:text="3"
            android:layout_weight="1"/>
        </LinearLayout>
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="9"
        android:layout_weight="1">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/material_blue_grey_800"
            android:text="1"
            android:layout_weight="1"
            android:textColor="@color/md_white_1000"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/material_blue_grey_800"
            android:text="2"
            android:textColor="@color/md_white_1000"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_yellow_100"
            android:textColor="@color/md_white_1000"
            android:text="3"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/material_blue_grey_800"
            android:text="1"
            android:layout_weight="1"
            android:textColor="@color/md_white_1000"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/material_blue_grey_800"
            android:text="2"
            android:textColor="@color/md_white_1000"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_yellow_100"
            android:textColor="@color/md_white_1000"
            android:text="3"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/material_blue_grey_800"
            android:text="1"
            android:layout_weight="1"
            android:textColor="@color/md_white_1000"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/material_blue_grey_800"
            android:text="2"
            android:textColor="@color/md_white_1000"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_yellow_100"
            android:textColor="@color/md_white_1000"
            android:text="3"
            android:layout_weight="1"/>



    </LinearLayout>


</LinearLayout>

1 个答案:

答案 0 :(得分:0)

我认为我做对了。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="2"
    android:orientation="horizontal">


    <LinearLayout
        android:id="@+id/left_image"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="25"
        android:layout_weight="1">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_black_1000"
            android:paddingRight="10dp"
            android:text="Here"
            android:layout_weight="1"
            android:gravity="center"
            android:textAlignment="gravity"
            android:textColor="@color/md_white_1000"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_purple_500"
            android:paddingRight="10dp"
            android:text="1"
            android:layout_weight="1"
            android:gravity="right"
            android:textAlignment="gravity"
            android:textColor="@color/md_white_1000"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_purple_500"
            android:text="2"
            android:paddingRight="10dp"
            android:gravity="right"
            android:textAlignment="gravity"
            android:textColor="@color/md_white_1000"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_purple_500"
            android:textColor="@color/md_white_1000"
            android:text="3"
            android:paddingRight="10dp"
            android:gravity="right"
            android:textAlignment="gravity"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_purple_500"
            android:text="4"
            android:paddingRight="10dp"
            android:gravity="right"
            android:textAlignment="gravity"
            android:layout_weight="1"
            android:textColor="@color/md_white_1000"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_purple_500"
            android:text="5"
            android:paddingRight="10dp"
            android:gravity="right"
            android:textAlignment="gravity"
            android:textColor="@color/md_white_1000"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_purple_500"
            android:textColor="@color/md_white_1000"
            android:text="6"
            android:paddingRight="10dp"
            android:gravity="right"
            android:textAlignment="gravity"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_purple_500"
            android:text="7"
            android:paddingRight="10dp"
            android:gravity="right"
            android:textAlignment="gravity"
            android:layout_weight="1"
            android:textColor="@color/md_white_1000"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_teal_500"
            android:text="8"
            android:paddingRight="10dp"
            android:gravity="right"
            android:textAlignment="gravity"
            android:textColor="@color/md_white_1000"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_teal_500"
            android:textColor="@color/md_white_1000"
            android:text="9"
            android:paddingRight="10dp"
            android:gravity="right"
            android:textAlignment="gravity"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_amber_500"
            android:text="10"
            android:paddingRight="10dp"
            android:gravity="right"
            android:textAlignment="gravity"
            android:layout_weight="1"
            android:textColor="@color/md_white_1000"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_amber_500"
            android:text="11"
            android:paddingRight="10dp"
            android:gravity="right"
            android:textAlignment="gravity"
            android:textColor="@color/md_white_1000"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_amber_500"
            android:textColor="@color/md_white_1000"
            android:text="12"
            android:paddingRight="10dp"
            android:gravity="right"
            android:textAlignment="gravity"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_amber_500"
            android:text="13"
            android:paddingRight="10dp"
            android:gravity="right"
            android:textAlignment="gravity"
            android:layout_weight="1"
            android:textColor="@color/md_white_1000"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_amber_500"
            android:text="14"
            android:paddingRight="10dp"
            android:gravity="right"
            android:textAlignment="gravity"
            android:textColor="@color/md_white_1000"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_amber_500"
            android:textColor="@color/md_white_1000"
            android:text="15"
            android:paddingRight="10dp"
            android:gravity="right"
            android:textAlignment="gravity"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_amber_500"
            android:text="16"
            android:paddingRight="10dp"
            android:gravity="right"
            android:textAlignment="gravity"
            android:layout_weight="1"
            android:textColor="@color/md_white_1000"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_amber_500"
            android:text="17"
            android:paddingRight="10dp"
            android:gravity="right"
            android:textAlignment="gravity"
            android:textColor="@color/md_white_1000"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_brown_500"
            android:textColor="@color/md_white_1000"
            android:text="18"
            android:paddingRight="10dp"
            android:gravity="right"
            android:textAlignment="gravity"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_brown_500"
            android:text="19"
            android:paddingRight="10dp"
            android:gravity="right"
            android:textAlignment="gravity"
            android:layout_weight="1"
            android:textColor="@color/md_white_1000"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_brown_500"
            android:text="20"
            android:paddingRight="10dp"
            android:gravity="right"
            android:textAlignment="gravity"
            android:textColor="@color/md_white_1000"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_brown_500"
            android:textColor="@color/md_white_1000"
            android:text="21"
            android:paddingRight="10dp"
            android:gravity="right"
            android:textAlignment="gravity"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_brown_500"
            android:text="22"
            android:paddingRight="10dp"
            android:gravity="right"
            android:textAlignment="gravity"
            android:layout_weight="1"
            android:textColor="@color/md_white_1000"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_brown_500"
            android:text="23"
            android:paddingRight="10dp"
            android:gravity="right"
            android:textAlignment="gravity"
            android:textColor="@color/md_white_1000"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_brown_500"
            android:textColor="@color/md_white_1000"
            android:text="24"
            android:paddingRight="10dp"
            android:gravity="right"
            android:textAlignment="gravity"
            android:layout_weight="1"/>

        </LinearLayout>
    <LinearLayout

        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="25"
        android:layout_weight="1">
        <TextView
            android:id="@+id/current_city"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_black_1000"
            android:paddingRight="10dp"
            android:text="New York"
            android:layout_weight="1"
            android:gravity="center"
            android:textAlignment="gravity"
            android:textColor="@color/md_white_1000"/>

        <TextView
            android:id="@+id/hour_1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_purple_500"
            android:text="1"
            android:paddingLeft="10dp"
            android:layout_weight="1"
            android:textColor="@color/md_white_1000"/>
        <TextView
            android:id="@+id/hour_2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_purple_500"
            android:text="2"
            android:paddingLeft="10dp"
            android:textColor="@color/md_white_1000"
            android:layout_weight="1"/>
        <TextView
            android:id="@+id/hour_3"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_purple_500"
            android:textColor="@color/md_white_1000"
            android:text="3"
            android:paddingLeft="10dp"
            android:layout_weight="1"/>
        <TextView
            android:id="@+id/hour_4"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_purple_500"
            android:text="4"
            android:paddingLeft="10dp"
            android:layout_weight="1"
            android:textColor="@color/md_white_1000"/>
        <TextView
            android:id="@+id/hour_5"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_purple_500"
            android:text="5"
            android:paddingLeft="10dp"
            android:textColor="@color/md_white_1000"
            android:layout_weight="1"/>
        <TextView
            android:id="@+id/hour_6"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_purple_500"
            android:textColor="@color/md_white_1000"
            android:text="6"
            android:paddingLeft="10dp"
            android:layout_weight="1"/>
        <TextView
            android:id="@+id/hour_7"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_purple_500"
            android:text="7"
            android:paddingLeft="10dp"
            android:layout_weight="1"
            android:textColor="@color/md_white_1000"/>
        <TextView
            android:id="@+id/hour_8"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_teal_500"
            android:text="8"
            android:paddingLeft="10dp"
            android:textColor="@color/md_white_1000"
            android:layout_weight="1"/>
        <TextView
            android:id="@+id/hour_9"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_teal_500"
            android:textColor="@color/md_white_1000"
            android:text="9"
            android:paddingLeft="10dp"
            android:layout_weight="1"/>
        <TextView
            android:id="@+id/hour_10"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_amber_500"
            android:text="10"
            android:paddingLeft="10dp"
            android:layout_weight="1"
            android:textColor="@color/md_white_1000"/>
        <TextView
            android:id="@+id/hour_11"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_amber_500"
            android:text="11"
            android:paddingLeft="10dp"
            android:textColor="@color/md_white_1000"
            android:layout_weight="1"/>
        <TextView
            android:id="@+id/hour_12"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_amber_500"
            android:textColor="@color/md_white_1000"
            android:text="12"
            android:paddingLeft="10dp"
            android:layout_weight="1"/>
        <TextView
            android:id="@+id/hour_13"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_amber_500"
            android:text="13"
            android:paddingLeft="10dp"
            android:layout_weight="1"
            android:textColor="@color/md_white_1000"/>
        <TextView
            android:id="@+id/hour_14"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_amber_500"
            android:text="14"
            android:paddingLeft="10dp"
            android:textColor="@color/md_white_1000"
            android:layout_weight="1"/>
        <TextView
            android:id="@+id/hour_15"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_amber_500"
            android:textColor="@color/md_white_1000"
            android:text="15"
            android:paddingLeft="10dp"
            android:layout_weight="1"/>
        <TextView
            android:id="@+id/hour_16"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_amber_500"
            android:text="16"
            android:paddingLeft="10dp"
            android:layout_weight="1"
            android:textColor="@color/md_white_1000"/>
        <TextView
            android:id="@+id/hour_17"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_amber_500"
            android:text="17"
            android:paddingLeft="10dp"
            android:textColor="@color/md_white_1000"
            android:layout_weight="1"/>
        <TextView
            android:id="@+id/hour_18"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_brown_500"
            android:textColor="@color/md_white_1000"
            android:text="18"
            android:paddingLeft="10dp"
            android:layout_weight="1"/>
        <TextView
            android:id="@+id/hour_19"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_brown_500"
            android:text="19"
            android:paddingLeft="10dp"
            android:layout_weight="1"
            android:textColor="@color/md_white_1000"/>
        <TextView
            android:id="@+id/hour_20"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_brown_500"
            android:text="20"
            android:paddingLeft="10dp"
            android:textColor="@color/md_white_1000"
            android:layout_weight="1"/>
        <TextView
            android:id="@+id/hour_21"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_brown_500"
            android:textColor="@color/md_white_1000"
            android:text="21"
            android:paddingLeft="10dp"
            android:layout_weight="1"/>
        <TextView
            android:id="@+id/hour_22"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_brown_500"
            android:text="22"
            android:paddingLeft="10dp"
            android:layout_weight="1"
            android:textColor="@color/md_white_1000"/>
        <TextView
            android:id="@+id/hour_23"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_brown_500"
            android:text="23"
            android:paddingLeft="10dp"
            android:textColor="@color/md_white_1000"
            android:layout_weight="1"/>
        <TextView
            android:id="@+id/hour_24"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/md_brown_500"
            android:textColor="@color/md_white_1000"
            android:text="24"
            android:paddingLeft="10dp"
            android:layout_weight="1"/>



    </LinearLayout>


</LinearLayout>