まず、この質問に重複しないようにしてください。これは、他の投稿とは1つの重要な点で異なります。誰かが、断片の色を真ん中の2つの色に分ける方法を知っていますか?みんな、ありがとう!ここAndroidの断片を2つの色に分割する方法
答えて
のように行うことができますを定義します。 .png
、それを私がそれが必要なときのための活動の背景として設定してください。シンプルで、きれいで、簡単で、いつも2色にする必要があるだけなので、画像が細くなることを心配する必要はありません。
は、第二次単にユーザーでframeLayoutのXMLあなたが少しを書き、ピクセルレベルでいくつかの作業をしなければならない第三の1については
<FrameLayout
android:id="@+id/fl_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/ll_test"
android:layout_width="200dp"
android:layout_height="100dp"
android:background="@android:color/white"
android:orientation="horizontal">
<View
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_weight="1"
android:background="@android:color/holo_red_dark" />
<View
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_weight="1"
android:background="@android:color/holo_blue_dark" />
</LinearLayout>
<TextView
android:id="@+id/tv_test2"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:background="@android:color/transparent"
android:gravity="center"
android:text="A"
android:textColor="@android:color/white"
android:textSize="100sp" />
</FrameLayout>
を達成するために、勾配
float in[] = new float[] {0f,1f};
TextView textView= (TextView)findViewById(R.id.tv_test);
Shader shader = new LinearGradient(
0, textView.getTextSize(), textView.getWidth(), textView.getHeight(), new int[]{Color.RED, Color.BLUE},in,
Shader.TileMode.CLAMP);
textView.getPaint().setShader(shader);
を使用するサンプルです
<TextView
android:id="@+id/tv_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="H"
android:textColor="@android:color/holo_red_dark"
android:textSize="100sp" />
<FrameLayout
android:id="@+id/fl_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/ll_test"
android:layout_width="200dp"
android:layout_height="100dp"
android:background="@android:color/white"
android:orientation="horizontal">
<View
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_weight="1"
android:background="@android:color/holo_red_dark" />
<View
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_weight="1"
android:background="@android:color/holo_blue_dark" />
</LinearLayout>
<TextView
android:id="@+id/tv_test2"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:background="@android:color/transparent"
android:gravity="center"
android:text="A"
android:textColor="@android:color/white"
android:textSize="100sp" />
</FrameLayout>
<ImageView
android:id="@+id/iv_test"
android:layout_width="200dp"
android:layout_height="200dp" />
あなたが正確に達成したい何
public class MainActivity extends AppCompatActivity {
View linearLayout;
View tvTest2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
TextView textView = (TextView) findViewById(R.id.tv_test);
Shader shader = new LinearGradient(
0, textView.getTextSize()/2, textView.getTextSize(), textView.getTextSize()/2,Color.RED, Color.BLUE,
Shader.TileMode.CLAMP);
textView.getPaint().setShader(shader);
linearLayout = findViewById(R.id.ll_test);
tvTest2 = findViewById(R.id.tv_test2);
}
@Override
protected void onResume() {
super.onResume();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
ImageView imageView = (ImageView) findViewById(R.id.iv_test);
Bitmap b1 = getBitmapFromView(linearLayout);
Bitmap b2 = getBitmapFromView(tvTest2);
imageView.setImageBitmap(textEffect(b1, b2));
}
},2000);
}
public Bitmap textEffect(Bitmap image, Bitmap text) {
if (image.getWidth() != text.getWidth() ||
image.getHeight() != text.getHeight()) {
throw new IllegalArgumentException("Dimensions are not the same!");
}
for (int y = 0; y < image.getHeight(); ++y) {
for (int x = 0; x < image.getWidth(); ++x) {
int textPixel = text.getPixel(x, y);
int imagePixl = image.getPixel(x,y);
int red = Color.red(textPixel);
int blue = Color.blue(textPixel);
int green = Color.green(textPixel);
int alpha = Color.alpha(textPixel);
Log.i("TAG", "textEffect: "+x+"-"+y+",-->"+red+","+blue+","+green+","+alpha);
/*Since text color is white so give the color of background to it
* else make it white*/
if (red == 255) {
if (blue == 255) {
if (green == 255) {
image.setPixel(x, y, imagePixl);
}else
{
image.setPixel(x, y, textPixel);
}
}else{
image.setPixel(x, y, textPixel);
}
}else
{
image.setPixel(x, y, textPixel);
}
}
}
return image;
}
public static Bitmap getBitmapFromView(View view) {
//Define a bitmap with the same size as the view
Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
//Bind a canvas to it
Canvas canvas = new Canvas(returnedBitmap);
//Get the view's background
Drawable bgDrawable = view.getBackground();
if (bgDrawable != null)
//has background drawable, then draw it on the canvas
bgDrawable.draw(canvas);
else
//does not have background drawable, then draw white background on the canvas
canvas.drawColor(Color.WHITE);
// draw the view on the canvas
view.draw(canvas);
//return the bitmap
return returnedBitmap;
}
}
のTextView
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="12dp"
android:text="O"
android:textColor="#88022b54"
android:textSize="250sp"
android:textStyle="bold"
android:shadowColor="#ff2e7cca"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="1"/>
その後
Shader shader = new LinearGradient(
0, mytv.getTextSize()/2, mytv.getTextSize(), mytv.getTextSize()/2,
Color.RED, Color.BLUE,
Shader.TileMode.CLAMP);
mytv.getPaint().setShader(shader);
私はおそらくこのコードを断片に適用できますか? – Ethan
私が知る限り、問題はありません。走っているのを見ましたか?はい、ほとんどあなたが望んでいたものですね。 – statosdotcom
いいえ私はあなたに私にリンクを送ることができませんでしたか?また、fragment_standardにコードを編集することはできますか?赤色が左半分に、青色が右半分になるように垂直に分割する必要があります – Ethan
あなたが、私はそれを保存し、Photoshopでの理想的な背景を作成することによって、これを達成し、この
String text = "<font color=#cc0029>Erste Farbe</font> <font color=#ffcc00>zweite Farbe</font>";
yourtextview.setText(Html.fromHtml(text));
- 1. イメージを断片に分割/カットする方法
- 2. Androidの二つの断片
- 3. メモリの断片化を解決するためのヒープ分割
- 4. 文字列を断片に分割する
- 5. リテラルを2つの部分に分割する方法
- 6. Androidの断片:他のフラグメントからの断片を置換
- 7. Androidの断片ですか?
- 8. Twitter4jをAndroidの断片と統合する方法は?
- 9. マップは断片に分割されます
- 10. AndroidのGoogleマップの断片
- 11. Androidの断片のビューステート
- 12. 同じ方法で断片と断片化を返す方法は?
- 13. Androidの断片とは、GetWindow()
- 14. 断片化されたMP4を複数のMP4ファイルに分割する
- 15. ツリーを2つのサブツリーに分割する方法
- 16. 断片化の方法にアクセスする方法
- 17. 断片について
- 18. 2つの符号なしshortを分割する方法
- 19. パイヤ暗号で2つの数を分割する方法は?
- 20. 4113.52318NをPHPで2つに分割する方法
- 21. ファイルを正規表現で2つに分割する方法
- 22. 断片化の計算方法は?
- 23. 1つの線を2つの部分に分割する
- 24. 文字列を壊すことなく断片に分割します。
- 25. Android、ListViewアイテムを3つの部分に分割する方法は?
- 26. HTMLの2つの異なる色を持つ2つの三角形のセルテーブルを分割する
- 27. Androidのアクションバータブの背景色分割モード
- 28. 2つの列に分割する
- 29. 主な活動2つの断片からデータを取得
- 30. Androidの断片の例startActivityは黙っ
@Shark Spannablesは1文字のレンダリングを分割して使用することはできません。それぞれの手紙のために物事を変えることができますが、それはOPが求めたものではありません。 –
@DougStevensonかなり、私はOPが何を頼んだかを本当にはっきりと理解していませんでした。私はまだ...オハイオ州、私は今それを得ると思います。例:彼は赤黒の「A」文字を左半分に赤色に、黒色を右半分にしたい。 – Shark
OPはそれが確かですか? "テキストビューの色を分割する"と私に言いますが、彼は文字レンダリングではなく、2つに分割したいと思うtextviewの背景です。彼はそれを意味するかもしれないが、それは明らかではない。 OP? –