add a bar in java rather than xml in Android



I want to show a fraction number, I found this XML code in many websites and it works well.



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:id="@+id/fractionLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >

<EditText
android:id="@+id/numinator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="1dp"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:layout_marginTop="0dp"
android:background="@null"
android:inputType="textNoSuggestions"
android:textColor="#ff000000"
android:textSize="15sp"
android:windowSoftInputMode="stateAlwaysHidden" />

<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#000000" />

<EditText
android:id="@+id/denominator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:layout_marginTop="0dp"
android:background="@null"
android:inputType="textNoSuggestions"
android:textColor="#ff000000"
android:textSize="15sp"
android:windowSoftInputMode="stateAlwaysHidden" />

</LinearLayout>


but I want to add the views dynamically in Java code, rather than inflater.inflate and then addView(layout). I can see how to add the Edittext:



EditText numinator = new EditText (this);
numinator.setText = "xxx";
numinator.setBackground = "xxx";
addView(numinator);


and so on... I cannot find methods in EditText that set its width to wrap content, but it seems to be default. But I cannot find any method in the class View to set its width to match parent or its height to 1dip or its background.


No comments:

Post a Comment