D
DMD-OL
Neues Mitglied
hi
ich möchte die Größe meiner App an die verschiedenen Handygrößen jeweils anpassen und
habe mich dazu an
adjust image button's margin,height and width programatically
gehalten.
Ich habe aber ein Problem die Höhe und Breite an ein Textfeld zu übergeben.
Ich habe es mit
How to set RelativeLayout layout params in code not in xml
versucht, was aber nicht so richtig klappt.
Mein Code in .java:
... in .xml:
Ich bekomm es nicht hin, so daß ich in der .xml die beiden layout_widht und layout_height auskommentieren kann
bzw. wie wird es korrekt gemacht?
ich möchte die Größe meiner App an die verschiedenen Handygrößen jeweils anpassen und
habe mich dazu an
adjust image button's margin,height and width programatically
gehalten.
Ich habe aber ein Problem die Höhe und Breite an ein Textfeld zu übergeben.
Ich habe es mit
How to set RelativeLayout layout params in code not in xml
versucht, was aber nicht so richtig klappt.
Mein Code in .java:
Code:
public class haupt extends AppCompatActivity {
private TextView arbeitstag_waehlen;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.haupt_main);
arbeitstag_waehlen = (TextView)findViewById(R.id.arbeitstag_waehlen);
Display display=((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int width=display.getWidth();
int height=display.getHeight();
int buttonWidth = width/5;
int buttonHeight = height/10;
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(buttonHeight, buttonWidth);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
arbeitstag_waehlen.setLayoutParams(params);
}
}
Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="myapplication.example.com.myapplication.haupt">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Eine Überschrift"
android:id="@+id/datenuebersicht"
android:layout_below="@+id/arbeitstag_waehlen"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true" />
</RelativeLayout>
bzw. wie wird es korrekt gemacht?