1

如何在 UI 中固定虚线的宽度?在我的屏幕虚线不完全适合屏幕宽度见下图。如果移动宽度很小,我手动TextView使用破折号移动到下一行,如果移动宽度很厚,下面的一些破折号会在右侧留下一些空间。

我的截图

我的代码如下:

  <ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/border5" >

            <ImageView
                android:id="@+id/test_button_image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:paddingLeft="5dp"
                android:src="@drawable/iicon" >
            </ImageView>

            <TextView
                android:id="@+id/test_button_text2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignTop="@+id/test_button_image"
                android:layout_toRightOf="@+id/test_button_image"
                android:paddingLeft="10dp"
                android:paddingTop="10dp"
                android:text="Description"
                android:textColor="#000000"
                android:textSize="15sp"
                android:textStyle="bold" >
            </TextView>

            <TextView
                android:id="@+id/test_button_text23"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/test_button_text2"
                android:layout_below="@+id/test_button_text2"
                android:paddingBottom="10dp"
                android:paddingLeft="10dp"
                android:text="-------------------------------------------------"
                android:textColor="#000000" >
            </TextView>

            <TextView
                android:id="@+id/description"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/test_button_text2"
                android:layout_below="@+id/test_button_text23"
                android:paddingBottom="10dp"
                android:paddingLeft="10dp"
                android:text=" "
                android:textColor="#000000" >
            </TextView>
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/border5" >

            <ImageView
                android:id="@+id/test_button_image20"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:paddingLeft="5dp"
                android:src="@drawable/iicon" >
            </ImageView>

            <TextView
                android:id="@+id/test_button_text12"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignTop="@+id/test_button_image20"
                android:layout_toRightOf="@+id/test_button_image20"
                android:paddingLeft="10dp"
                android:paddingTop="10dp"
                android:text="Contains"
                android:textColor="#000000"
                android:textSize="15sp"
                android:textStyle="bold" >
            </TextView>

            <TextView
                android:id="@+id/test_button_text5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/test_button_text12"
                android:layout_toRightOf="@+id/test_button_image20"
                android:paddingBottom="10dp"
                android:paddingLeft="10dp"
                android:text="---------------------------------------"
                android:textColor="#000000" >
            </TextView>

            <com.schoollunchapp.HorizontalListView
                android:id="@+id/listview2"
                android:layout_width="wrap_content"
                android:layout_height="150dp"
                android:layout_below="@+id/test_button_text5"
                android:background="#ffffff" />
        </RelativeLayout>
4

2 回答 2

1

我试图创建虚线,但不确定它是否完全符合您的要求。

可绘制/dotted.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">

    <stroke
       android:color="#C7B299"
       android:dashWidth="10px"
       android:dashGap="10px" />
</shape>

视图.xml:

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/dotted" /> 

如需更多理解,请参阅此答案。希望能帮助到你。

于 2013-08-16T12:26:16.867 回答
0

这对我有用:)

可绘制/dotted.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line">

    <stroke
        android:dashWidth="10dp"
        android:dashGap="9dp"
        android:width="3dp"
        android:color="#757575" />
</shape>

布局/my_activity.xml:

<ImageView
    android:layout_width="match_parent"
    android:layout_height="35dp"
    android:src="@drawable/dotted" />
于 2019-08-24T19:42:21.717 回答