У меня возникли проблемы с созданием указанного ниже макета Android с кодом.

<RelativeLayout
    android:id="@+id/profile_info_gender"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:id="@+id/ProfileTable"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#D9D9D9"
        android:baselineAligned="false"
        android:orientation="horizontal" >

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="0.5"
            android:background="#F3F3F3"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/gender_txt"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:layout_marginTop="8dp"
                android:textColor="@color/info_left"
                android:textSize="14sp"
                android:textStyle="bold" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:layout_weight="0.5"
            android:background="@color/white"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/profile_info_text_gender"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:layout_marginTop="8dp"
                android:textSize="14sp" />
        </RelativeLayout>
    </LinearLayout>
</RelativeLayout>

Я пробовал много вещей из Google и блогов, но не смог закончить с этим макетом, любая помощь будет высоко оценена, и ею будут восхищаться спасибо

0
Shoaib 27 Мар 2014 в 10:20
1
Вы пробовали xmltojava.com?
 – 
pskink
27 Мар 2014 в 10:30
Конвертация не работает :(
 – 
Shoaib
27 Мар 2014 в 10:34
Какой смысл иметь верхний RelativeLayout только с одним дочерним элементом: LinearLayout, у которого есть только один дочерний элемент: другой RelativeLayout?
 – 
pskink
27 Мар 2014 в 10:47
1
Подсказка: не используйте визуальный редактор для создания макетов xml, делайте это вручную, так вы лучше поймете, как работают макеты
 – 
pskink
27 Мар 2014 в 11:06
1
Посмотри мой ответ..
 – 
Hariharan
27 Мар 2014 в 11:13

2 ответа

Лучший ответ

Попробуй это..

    LinearLayout first_lay = new LinearLayout(this);

    LinearLayout.LayoutParams lp_icon = new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.MATCH_PARENT, 
              LinearLayout.LayoutParams.MATCH_PARENT);

    first_lay.setOrientation(LinearLayout.HORIZONTAL);
    first_lay.setLayoutParams(lp_icon);

    LinearLayout left_lay = new LinearLayout(this);

    LinearLayout.LayoutParams left_icon = new LinearLayout.LayoutParams(
              0, 
              LinearLayout.LayoutParams.WRAP_CONTENT,1);

    left_lay.setGravity(Gravity.CENTER);

    left_lay.setBackgroundColor(Color.parseColor("#696969"));

    left_lay.setLayoutParams(left_icon);


     LinearLayout.LayoutParams tests = new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.WRAP_CONTENT, 
              LinearLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER);

     TextView text1 = new TextView(this);
     left_lay.addView(text1);
     text1.setLayoutParams(tests);
     text1.setText("Left Text");
     text1.setTextSize(18);

     first_lay.addView(left_lay);

     LinearLayout right_lay = new LinearLayout(this);

    LinearLayout.LayoutParams right_icon = new LinearLayout.LayoutParams(
              0, 
              LinearLayout.LayoutParams.WRAP_CONTENT,1);

    right_lay.setGravity(Gravity.CENTER);

    right_lay.setBackgroundColor(Color.parseColor("#D9D9D9"));

    right_lay.setLayoutParams(right_icon);

    TextView text2 = new TextView(this);
    right_lay.addView(text2);
     text2.setLayoutParams(tests);
     text2.setText("Right Text");
     text2.setTextSize(18);

     first_lay.addView(right_lay);
1
Hariharan 27 Мар 2014 в 11:06
Не был точным ответом, но помог мне, спасибо, харихаран :)
 – 
Shoaib
27 Мар 2014 в 17:00

Почему бы не сделать это:

RelativeLayout profile_info_gender =  new RelativeLayout(your activity);
LinearLayout ProfileTable = new LinearLayout(your activity);
profile_info_gender.addView(ProfileTable);

Для ориентации используйте LayoutParams.

0
Substantial 8 Ноя 2014 в 14:40
Одно небольшое замечание: для хорошо читаемых представлений кодового имени со строчными буквами profileTable
 – 
Lucian Novac
27 Мар 2014 в 10:42