我該如何在android xml文件中編寫這個--------或--------。雖然我用連字符,但會有一條線,然後或然後線(請參閱圖像鏈接)xml文件中的Android線條繪製錯誤
我已經看到了一些答案在這裏在stackoverflow但他們只是線和文本不在裏面。所以我找不到我的答案。
鏈接:https://docs.google.com/document/d/1_sWfoxiwU4jZmokH0lmtAkEUiXU2N-2QTDpL9NsMj_g/edit
我該如何在android xml文件中編寫這個--------或--------。雖然我用連字符,但會有一條線,然後或然後線(請參閱圖像鏈接)xml文件中的Android線條繪製錯誤
我已經看到了一些答案在這裏在stackoverflow但他們只是線和文本不在裏面。所以我找不到我的答案。
鏈接:https://docs.google.com/document/d/1_sWfoxiwU4jZmokH0lmtAkEUiXU2N-2QTDpL9NsMj_g/edit
<View
android:layout_width="100dp"
android:layout_height="1dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="or"/>
<View
android:layout_width="100dp"
android:layout_height="1dp"
/>
您可以使用類似這樣
當然可以。使用此
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:width="1dp"
android:color="#999999"
android:dashGap="2dp"
android:dashWidth="2dp" />
<solid android:color="@android:color/transparent" />
,然後在視圖中,使用layerType = 「軟件」 設置可繪製作爲背景。
<android:layout_width="match_parent"
android:layout_height="3dp"
android:background="@drawable/line_promo"
android:layerType="software" />
試試這個,
像這樣創建一個XML可繪製。
繪製/ _line.xml
<layer-list xmlns:android = "http://schemas.android.com/apk/res/android">
<item
android:bottom = "-1dp"
android:left = "-1dp"
android:right = "-1dp"
android:top = "0dp">
<shape android:shape = "line">
<stroke
android:width = "1dp"
android:color = "#000"
android:dashGap = "0dp"
android:dashWidth = "5dp"/>
<solid android:color = "@android:color/transparent"/>
<padding
android:bottom = "10dp"
android:left = "10dp"
android:right = "10dp"
android:top = "10dp"/>
</shape>
</item>
</layer-list>
然後在你的佈局文件創建視圖,設置上述XML作爲繪製它這樣。
your_layout_file.xml
<LinearLayout
xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:background = "#ffffff"
android:gravity = "center"
android:orientation = "horizontal">
<View
android:layout_width = "50dp"
android:layout_height = "5dp"
android:background = "@drawable/_line"/>
<TextView
android:id = "@+id/tv"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_gravity = "center"
android:layout_marginLeft = "@dimen/pad_5"
android:layout_marginRight = "@dimen/pad_5"
android:gravity = "center"
android:text = "or"
android:textSize = "24sp"/>
<View
android:layout_width = "50dp"
android:layout_height = "5dp"
android:background = "@drawable/_line"/>
</LinearLayout>
希望這會幫助你,
工作!如果它有效,非常感謝 –
。請接受它。 –
2'View'用指定寬度和高度以及TextView的在中間,跟着這樣的:'視圖(保證金)的TextView (保證金)視圖' –
你知道嗎? –
對不起,我不明白。你能寫出XML嗎?我試過查看但只繪製了一條線 –