SORU
23 Temmuz 2011, CUMARTESİ


Program aracılığıyla bir Düzen boyutunu ayarlamak için Nasıl Android:

Android Uygulaması bir parçası olarak bir düğme set yapıyorum. Düğmeleri LinearLayouts iç içe geçmiş bir dizi parçasıdır. Ağırlık kullanarak set otomatik olarak kendini içeren üst LinearLayout boyutuna göre yeniden boyutlandırma. Fikir, dayalı piksel sayısı ve yoğunluğu ekran, set boyutu içeren belge sayısı piksel; ve set düğmesine yeniden boyutlandırmak kendisi göre değişir.

Düzeni yeniden boyutlandırmak için Nasıl. o zaman soru şu:

Birkaç önerilen yöntemler denedim ve bir işe yaramıyor yaklaşabilir. Burada düğme kümesi oluşturur XML bir alt kümesi:

    <LinearLayout android:layout_height="104pt" android:id="@ id/numberPadLayout" android:orientation="horizontal" android:layout_width="104pt"
    android:background="#a0a0a0"
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true"
>

    <LinearLayout android:layout_weight="2" android:layout_height="fill_parent" android:id="@ id/linearLayout1" android:orientation="vertical" android:layout_width="wrap_content">
        <Button android:text="1" android:id="@ id/button1" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
        <Button android:text="4" android:id="@ id/button4" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
        <Button android:text="7" android:id="@ id/button7" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
        <Button android:text="-" android:id="@ id/buttonDash" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
    </LinearLayout>
    <LinearLayout android:layout_weight="2" android:layout_height="fill_parent" android:id="@ id/linearLayout2" android:orientation="vertical" android:layout_width="wrap_content">
        <Button android:text="2" android:id="@ id/button2" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
        <Button android:text="5" android:id="@ id/button5" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
        <Button android:text="8" android:id="@ id/button8" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
        <Button android:text="0" android:id="@ id/button0" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
    </LinearLayout>

    <LinearLayout android:layout_weight="2" android:layout_height="fill_parent" android:id="@ id/linearLayout3" android:orientation="vertical" android:layout_width="wrap_content">
        <Button android:text="3" android:id="@ id/button3" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
        <Button android:text="6" android:id="@ id/button6" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
        <Button android:text="9" android:id="@ id/button9" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
        <Button android:text="." android:id="@ id/buttonDot" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
    </LinearLayout>
    <LinearLayout android:layout_weight="2" android:layout_height="fill_parent" android:id="@ id/linearLayout4" android:orientation="vertical" android:layout_width="wrap_content">
        <Button android:text="/" android:id="@ id/buttonBack" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
        <Button android:text="\" android:id="@ id/buttonEnter" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
    </LinearLayout>

</LinearLayout>    

İki soru vardır: 1) nasıl Java numberPadLayout erişebilir. Ve erişimi var bir kere görmek, 2) nasıl düzen genişliği ve yüksekliği değiştirebilirim.

Herhangi bir öneri takdir edilecektir.

CEVAP
23 Temmuz 2011, CUMARTESİ


Bu çalışması gerekir:

// Gets linearlayout
LinearLayout layout = (LinearLayout)findViewById(R.id.numberPadLayout);
// Gets the layout params that will allow you to resize the layout
LayoutParams params = layout.getLayoutParams();
// Changes the height and width to the specified *pixels*
params.height = 100;
params.width = 100;

Eğer piksel dip dönüştürmek istiyorsanız, bu kullanın:

int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, <HEIGHT>, getResources().getDisplayMetrics());

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • FPSRussia

    FPSRussia

    19 NİSAN 2010
  • Fuse

    Fuse

    21 Kasım 2005
  • taliajoy18

    taliajoy18

    12 Temmuz 2011