2010-09-07 20 views
7

मैं एक बिटमैप का उपयोग करना चाहता हूं जो केवल क्षैतिज पर टाइल है, ऐसा करने का कोई तरीका है, ताकि यह केवल एक्स पर सीएसएस पर दोहराने वाले एक्स की तरह विस्तारित हो सके। मैं निम्नलिखित कोड लेकिन बिटमैप टाइल का उपयोग करके क्षैतिज और ऊर्ध्वाधर:एक्स पर एंड्रॉइड बिटमैप टाइल केवल

<?xml version="1.0" encoding="utf-8"?> 
<bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
    android:src="@drawable/pinstripe" 
    android:tileMode="repeat" 
    android:gravity ="top|fill_horizontal" 
    android:dither="true"/> 
+0

में आप कभी भी एक समाधान यह पता लगाने की थी? – William

उत्तर

10

यहाँ समाधान है। आप कोड में बिटमैप ड्रायबल बना सकते हैं और केवल एक्स टाइल मोड Android Tile Bitmap

+6

+1 फेडरर: वर्तमान में एक्सएमएल में स्वतंत्र एक्स और वाई टाइल मोड निर्दिष्ट करने का कोई तरीका नहीं है। – Buzzy

0

मैं पृष्ठभूमि को केवल लंबवत रूप से दोहराना चाहता था, लेकिन मुझे वहां कोई सभ्य समाधान नहीं मिला, इसलिए मैंने इसे स्वयं लिखा, उम्मीद है कि यह मदद कर सकता है किसी को वहाँ बाहर *

/** 
* Created by LeoLink on 2014-06-24. 
*/ 
public class VerticallyRepeatedBackgroundLinearLayout extends LinearLayout { 
    private int width, height; 
    private RectF mRect; 

    public VerticallyRepeatedBackgroundLinearLayout(Context context) { 
     super(context); 
     init(context); 
    } 

    public VerticallyRepeatedBackgroundLinearLayout(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     init(context); 
    } 

    public VerticallyRepeatedBackgroundLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
     init(context); 
    } 

    private void init(Context context) { 
     setWillNotDraw(false); 
     mRect = new RectF(); 
    } 

    @Override 
    protected void onSizeChanged(int w, int h, int oldw, int oldh) { 
     super.onSizeChanged(w, h, oldw, oldh); 
     if (oldw == 0 && oldh == 0 && w > 0 && h > 0) { 
      width = w; 
      height = h; 
     } 
    } 

    @Override 
    protected void onDraw(Canvas canvas) { 
     super.onDraw(canvas); 
     // clear the canvas 
     canvas.drawColor(Color.WHITE); 
     // draw 
     Drawable bg = getBackground(); 
     Bitmap bm = ((BitmapDrawable)bg).getBitmap(); 
     int w = bg.getIntrinsicWidth(); 
     int h = bg.getIntrinsicHeight(); 
     int drawWidth = width; 
     int drawHeight = drawWidth * h/w; 
     int bottom = 0; 
     while (height > bottom) { 
      mRect.set(0, bottom, drawWidth, bottom + drawHeight); 
      canvas.drawBitmap(bm, null, mRect, null); 
      bottom += drawHeight; 
     } 
    } 
} 

और अपने एक्सएमएल

<com.blah.blah.VerticallyRepeatedBackgroundLinearLayout 
    android:id="@+id/collection_container" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/your_tile_bg"> 
</com.blah.blah.VerticallyRepeatedBackgroundLinearLayout> 
संबंधित मुद्दे