如何在充满宽度的 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>
最佳答案
我尝试创建虚线,但不确定它是否完全符合您的要求。
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/