質問

このように見えるカスタムビューをデザインしたい:

enter image description here

私は解決策を検索しました、そして私が得たのは EditText カスタマイズします。 Androidのメモ帳エディターの例を調べましたが、分割したいのであまり役に立ちませんでした EditText 少なくとも4つの部分に。

上のものはどこですか MDEG 書かれているのは、正しい部分はx10^012が書かれている場所、左部には現在の操作が含まれ、最後の部分は数字がオンになっている最大の部分です。

ただし、適切に行うために私を正しい方向に導き、このカスタムビューを設計するために基本クラスとして使用すべき事前に構築されたビューを教えてほしい。どんな助けも感謝します。

役に立ちましたか?

解決

1つの可能性は、拡張することです RelativeLayout クラスとコンストラクターでXMLレイアウトを膨らませます。

<RelativeLayout>
   <TextView /> // M     DEG(or 2 `TextView`)
   <ImageButton /> //ImageView for the operation
   <TextView /> //the digits
   <TextView /> //the extra digits 10^12
</RelativeLayout>

カスタム RelativeLayout クラス:

public class CustomView1 extends RelativeLayout {

    public CustomView1(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.lcd_layout, this, true);

        TextView part1 = (TextView) findViewById(R.id.the_id);
        //other stuff
    }

    public CustomView1(Context context, AttributeSet attrs) {
        this(context, attrs, 0);        
    }

    public CustomView1(Context context) {
        this(context, null);        
    }

}

他のヒント

レイアウトでそれを設計しないのはなぜですか?いくつかを積み重ねます LinearLayouts 互いの上に?

編集 国境の質問の例:

これをRES/描画可能なフォルダーに入れます:

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape>
            <gradient
                android:startColor="@color/c1"
                android:endColor="@color/c2"
                android:angle="270" />
             <stroke
                android:width="1dp"
                android:color="@color/stroke_color" />
        </shape>
</item>

</selector>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top