У меня возникли проблемы с созданием указанного ниже макета 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 и блогов, но не смог закончить с этим макетом, любая помощь будет высоко оценена, и ею будут восхищаться спасибо
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);
Почему бы не сделать это:
RelativeLayout profile_info_gender = new RelativeLayout(your activity);
LinearLayout ProfileTable = new LinearLayout(your activity);
profile_info_gender.addView(ProfileTable);
Для ориентации используйте LayoutParams
.
Похожие вопросы
Новые вопросы
android
Android — это мобильная операционная система Google, используемая для программирования или разработки цифровых устройств (смартфонов, планшетов, автомобилей, телевизоров, одежды, очков, IoT). Для тем, связанных с Android, используйте теги, специфичные для Android, такие как android-intent, android-activity, android-adapter и т. д. Для вопросов, отличных от разработки или программирования, но связанных с Android framework, используйте эту ссылку: https://android .stackexchange.com.