SORU
2 HAZİRAN 2010, ÇARŞAMBA


Android - LinearLayout çocuk Yatay kaydırma ile

Bir özellik düzgün çocuk kontrolleri şal sağlayacak Android LinearLayout için set var mı?

Anlamı - çocuk değişken sayı var ve bunları yatay gibi düzenlemek istiyor:

Example: Control1, Control2, Control3, ...

Ayarlayarak yapıyorum:

ll.setOrientation(LinearLayout.HORIZONTAL);
foreach (Child c in children)
  ll.addView(c);

Eğer çocuk çok sayıda varsa ancak, son kesti, sonraki satıra gitmek yerine birini alır.

Bu sabit olabilir nasıl herhangi bir fikir?

CEVAP
3 HAZİRAN 2010, PERŞEMBE


Davranış: bu tür ihtiyaç duyan herkes için

private void populateLinks(LinearLayout ll, ArrayList collection, String header) {

    Display display = getWindowManager().getDefaultDisplay();
    int maxWidth = display.getWidth() - 10;

    if (collection.size() > 0) {
        LinearLayout llAlso = new LinearLayout(this);
        llAlso.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));
        llAlso.setOrientation(LinearLayout.HORIZONTAL);

        TextView txtSample = new TextView(this);
        txtSample.setText(header);

        llAlso.addView(txtSample);
        txtSample.measure(0, 0);

        int widthSoFar = txtSample.getMeasuredWidth();
        for (Sample samItem : collection) {
            TextView txtSamItem = new TextView(this, null,
                    android.R.attr.textColorLink);
            txtSamItem.setText(samItem.Sample);
            txtSamItem.setPadding(10, 0, 0, 0);
            txtSamItem.setTag(samItem);
            txtSamItem.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    TextView self = (TextView) v;
                    Sample ds = (Sample) self.getTag();

                    Intent myIntent = new Intent();
                    myIntent.putExtra("link_info", ds.Sample);
                    setResult("link_clicked", myIntent);
                    finish();
                }
            });

            txtSamItem.measure(0, 0);
            widthSoFar  = txtSamItem.getMeasuredWidth();

            if (widthSoFar >= maxWidth) {
                ll.addView(llAlso);

                llAlso = new LinearLayout(this);
                llAlso.setLayoutParams(new LayoutParams(
                        LayoutParams.FILL_PARENT,
                        LayoutParams.WRAP_CONTENT));
                llAlso.setOrientation(LinearLayout.HORIZONTAL);

                llAlso.addView(txtSamItem);
                widthSoFar = txtSamItem.getMeasuredWidth();
            } else {
                llAlso.addView(txtSamItem);
            }
        }

        ll.addView(llAlso);
    }
}

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

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • thelonelyisland

    thelonelyisl

    23 Aralık 2005
  • TV nEW

    TV nEW

    25 AĞUSTOS 2012
  • UniqueApps

    UniqueApps

    4 Ocak 2009