Dynamisches Layout

P

padde83

Ambitioniertes Mitglied
0
Hallo zusammen,

ich arbeite gerade an einem TabellenLayout das aus vielen LinearLayouts zusammen gesetzt ist. Warum so umständlich?

Siehe hier https://www.android-hilfe.de/forum/android-app-entwicklung.9/ratingbar-in-tablerow.36827.html :D

Da ich MultiScreenSupport für die App bieten möchte, muss ich vom codierten Layout Abstand gewinnen.

Nun meine Frage.
Wie gewinne ich abstand von z.b. solche dingen:
Code:
..
params.setMargins(2, 2, 2, 2);

..

TextView textView = new TextView(Activity.this);
                           textView.setText(text);
                            textView.setTextAppearance(getApplicationContext(),
                                    android.R.style.TextAppearance_Small);
                            textView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD), Typeface.BOLD);
                            textView.setTextColor(Color.argb(200, 0, 0, 0));
                            textView.setEms(7);
                            textView.setMaxLines(2);
                            textView.setMinLines(2);
Meine Überlegung wäre evtl. verschiedene res/values Ordner
z.b.
res/values-small-ldpi
res/values-small-mdpi
..
und dort die Attribute reinpacken.

später dann mit getApplicationContext().getResources().getInteger(R.attr.myint);

darauf zugreifen.

Gibt es noch eine andere bessere Möglichkeit bzw. eine mit weniger Aufwand?:D

Gruß & Danke
padde83
 
du kannst die deinen abstand ausrechnen... ein wenig google hätte auch geholfen...

Converting from dips to pixels

In some cases, you will need to express dimensions in dip and then convert them to pixels. Imagine an application in which a scroll gesture is recognized after the user's finger has moved by at least 16 pixels. On a baseline screen, the user will have to move his finger by 16 pixels / 160 dpi = 1/10th of an inch (or 2.5 mm) before the gesture is recognized. On a device with a high (240) density display, the user will move his finger by only 16 pixels / 240 dpi = 1/15th of an inch (or 1.7 mm.) The distance is much shorter and the application thus appears more sensitive to the user. To fix this issue, the gesture threshold must be expressed in the code in dip and then converted to actual pixels.
// The gesture threshold expressed in dip
private static final float GESTURE_THRESHOLD_DIP = 16.0f;

// Convert the dips to pixels
final float scale = getContext().getResources().getDisplayMetrics().density;
mGestureThreshold = (int) (GESTURE_THRESHOLD_DIP * scale + 0.5f);

// Use mGestureThreshold as a distance in pixels
 
danke für die Antwort.
Google habe ich auch schon selber bemüht und das gleiche rausgefunden. :o

Leider hat es mir nicht wirklich geholfen. Aber evtl. hilft ja eine Nacht schlaf.

p.s. habe es nun wie oben schon beschrieben mit verschiedenen res/values Ordnern gelöst.
Vielleicht nicht die eleganteste Methode aber aktuell funktioniert es .:D

gruß
padde83
 

Ähnliche Themen

L
Antworten
4
Aufrufe
1.333
lonnie9020
L
A
Antworten
1
Aufrufe
881
koje71
koje71
M
  • maksimilian
Antworten
3
Aufrufe
1.124
maksimilian
M
Zurück
Oben Unten