我正在使用以下內容來處理文本。Android:刪除粗體或粗線的文本STRIKE_THRU_TEXT_FLAG
viewHolder.price_red.setPaintFlags(viewHolder.price_red
.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
它的工作,但我想通過線增加罷工的大小。
任何人都可以幫助我如何增加線的大小?
我正在使用以下內容來處理文本。Android:刪除粗體或粗線的文本STRIKE_THRU_TEXT_FLAG
viewHolder.price_red.setPaintFlags(viewHolder.price_red
.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
它的工作,但我想通過線增加罷工的大小。
任何人都可以幫助我如何增加線的大小?
您不能更改刪除線的粗細。
正如你可以從docs看到它的一面旗幟。無論是開還是關。
有一對夫婦的,雖然(比解決方案的更多黑客)選項:
使文本加粗或中風它。這樣會自動劃過刪除線,這會使其更加明顯。
手工畫線drawLine
。 (雖然這確實很難做到)
感謝@carl其有用的答案.. +1給予解決方案也。 –
這不能直接實現,因爲Android不提供任何相同的API。
現在,你將不得不去自定義的方式畫出較粗的線。1)的DrawLine 2)使用線圖像上的EditText
我已經使用EditText
和下RelativeLayout
一個ImageView
嘗試,它相當工作很適合我。
XML代碼:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/etStrike"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="Strike Thru Text Here"
android:textColor="@color/blacktext"
android:textSize="20sp" />
<ImageView
android:id="@+id/ivStrike"
android:layout_width="wrap_content"
android:layout_height="6dp"
android:layout_centerInParent="true"
android:background="@color/blacktext" />
</RelativeLayout>
Java代碼:
EditText etStrike = (EditText)findViewById(R.id.etStrike);
ImageView ivStrike = (ImageView)findViewById(R.id.ivStrike);
float textSize = etStrike.getTextSize()/2;
int textLength = etStrike.getText().length();
int totalLengthApprox = (int) (textLength * textSize)-textLength;
int height = 6; // YOUR_REQUIRED_HEIGHT
RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(totalLengthApprox,height);
param.addRule(RelativeLayout.CENTER_VERTICAL|RelativeLayout.ALIGN_PARENT_LEFT);
param.setMargins((int)textSize, 0, 0, 0);
ivStrike.setLayoutParams(param);
我已經測試只有少數TextSize
和Device Resolutions
也是最重要的,這隻能連續工作單線的EditText用於多邏輯就變得更復雜。
下面是如何去做:使用圖層列表和地方作爲您的textview背景。這裏我假設你textviews背景爲白色(#FFFFFF)
創建的文件夾可繪製一個名爲 strikethru.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#FFFFFF"/>
</shape>
</item>
<item>
<shape android:shape="line">
<stroke android:width="1dp"
android:color="#8d8d8d"/> <!-- adjust color you want here -->
</shape>
</item>
</layer-list>
然後在您的TextView做到這一點:
<TextView
android:id="@+id/tv_toolbar_prod_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="3dp"
android:text="1,290 B"
android:background="@drawable/strikethru_line"
android:textColor="#070707"
android:textSize="13sp" />
3dp的填充權使得穿透更加明顯。
按尺寸你是指厚度? – cjds
@CarlSaldanha是線條粗細。 –