android - 如何根据屏幕宽度调整虚线

标签 android

如何在充满宽度的 UI 中固定虚线?在我的屏幕上,虚线与屏幕宽度不完全吻合,请参见下图。如果移动宽度较小,我手动使用 TextView 作为破折号移动到下一行,如果移动宽度较厚,则会在右侧留下一些空间,如下所示。

My screenshot

我的代码如下:

  <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>

最佳答案

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

drawable/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>

view.xml:

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

要了解更多信息,请参阅 this answer .希望对您有所帮助。

关于android - 如何根据屏幕宽度调整虚线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18273068/

相关文章:

java - Android Studio 错误 : Activity must extend android. app.activity

android - Cordova-plugin-camera 不适用于 Android 版本 8

android - 相对缩放 View 及其分层 subview

android - 如何在 java 中以编程方式设置微光布局持续时间?

java - Android - 使用事件创建自定义日历

android - 使用 gnu libstdc++ 编译 NDK 代码

java - Android Studio 确定 GitHub 的凭据无效

java - float 百分比产生错误答案

javascript - 在android studio Assets 中调用.js文件中的javascript方法

android - 在 Android 中步行/驾驶时更新位置标记并在 Google map 上绘制路径