2017-06-13 104 views
-3

我是android编程的新手,我想在android中创建UI而不使用xml文件。我有以下用户界面与XML可以创建相同的用户界面编程,有没有其他方式做呢?一些参考文献将非常有帮助。在android中不使用XML创建UI

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginTop="2dp" 
    android:layout_marginRight="5dp" 
    android:layout_marginLeft="5dp" 
    android:weightSum="1"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="110dp" 
     android:tag="images" 
     android:orientation="horizontal"> 

     <ImageView 
      android:id="@+id/imageView2" 
      android:layout_width="163dp" 
      android:layout_height="86dp" 
      app:srcCompat="logo1" /> 

     <ImageView 
      android:id="@+id/imageView3" 
      android:layout_marginTop="10dp" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:srcCompat="logo2" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:tag="info1" 
     android:weightSum="1"> 

     <TextView 
      android:id="@+id/textView" 
      android:layout_width="match_parent" 
      android:layout_height="30dp" 
      android:textAlignment="center" 
      android:layout_marginBottom="5dp" 
      android:text="some text" 
      android:textSize="10pt" /> 

     <TextView 
      android:id="@+id/multilineText" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textAlignment="textStart" 
      android:layout_gravity="start" 
      android:text="additonal Text" 
      android:textSize="10pt"/> 

     <TextView 
      android:id="@+id/Text" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textAlignment="textStart" 
      android:layout_gravity="start" 
      android:layout_marginTop="3dp" 
      android:text="additional info 1" 
      android:textSize="10pt"/> 

     <TextView 
      android:id="@+id/enterText" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textAlignment="textStart" 
      android:layout_marginTop="10dp" 
      android:layout_gravity="start" 
      android:text="@string/prompt" 
      android:textSize="10pt"/> 

     <EditText 
      android:id="@+id/editText" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:inputType="password" 
      android:hint="hint" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <Button 
      android:id="@+id/button" 
      android:layout_width="match_parent" 
      android:layout_height="50dp" 
      android:layout_marginLeft="6dp" 
      android:layout_marginTop="12dp" 
      android:layout_weight="0.10" 
      android:background="@color/darkBlue" 
      android:text="Verify" /> 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="match_parent" 
      android:layout_height="50dp" 
      android:layout_marginLeft="6dp" 
      android:layout_marginTop="12dp" 
      android:background="@color/grey" 
      android:text="retry" /> 
    </LinearLayout> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_marginTop="10dp" 
     android:orientation="vertical" 
     android:layout_marginLeft="6dp" 
     android:layout_weight="0.58"> 

     <ScrollView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal"> 

      <com.ms.square.android.expandabletextview.ExpandableTextView 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:expandableTextView="http://schemas.android.com/apk/res-auto" 
       android:id="@+id/expand_text_view" 
       android:layout_width="350dp" 
       android:layout_height="wrap_content" 
       android:textAlignment="center" 
       expandableTextView:animDuration="500" 
       expandableTextView:maxCollapsedLines="1"> 

       <TextView 
        android:id="@id/expandable_text" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="10dp" 
        android:layout_marginRight="10dp" 
        android:textColor="#0d0d0d" 
        android:textSize="16dp" /> 

       <ImageButton 
        android:id="@id/expand_collapse" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="right|bottom" 
        android:background="@android:color/transparent" 
        android:padding="16dp" /> 
      </com.ms.square.android.expandabletextview.ExpandableTextView> 
     </ScrollView> 

     <View 
      android:layout_width="fill_parent" 
      android:layout_height="2dip" 
      android:background="@color/grey" /> 


     <ScrollView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal"> 

      <com.ms.square.android.expandabletextview.ExpandableTextView 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:expandableTextView="http://schemas.android.com/apk/res-auto" 
       android:id="@+id/expand_text_view2" 
       android:layout_width="350dp" 
       android:layout_height="wrap_content" 
       android:textAlignment="center" 
       expandableTextView:animDuration="500" 
       expandableTextView:maxCollapsedLines="1"> 

       <TextView 
        android:id="@id/expandable_text" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="10dp" 
        android:layout_marginRight="10dp" 
        android:textColor="#0d0d0d" 
        android:textSize="16dp" /> 

       <ImageButton 
        android:id="@id/expand_collapse" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="right|bottom" 
        android:background="@android:color/transparent" 
        android:padding="16dp" /> 
      </com.ms.square.android.expandabletextview.ExpandableTextView> 
     </ScrollView> 
    </LinearLayout> 

</LinearLayout> 
+0

我想更改UI元素的属性,如按钮颜色,运行时的文本大小 – Shailesh

回答

0

在屏幕的下方有两个标签:设计和文本 单击设计选项卡上,你可以从那里修改,而不会触及XML。 见附图。 enter image description here