Ссылка на мое изображение Мой макет в представлении «Дизайн» не отображается так, как в представлении «Дизайн» в эмуляторе пожалуйста помоги. Мне нужен точный макет. Я знаю, что это очень просто, но где я ошибаюсь. Я пытался сделать с линейным макетом, но та же проблема сохраняется, и да, извините за мой английский :(
<?xml version = "1.0" encoding = "utf-8"?>
<RelativeLayout android:layout_width = "wrap_content"
android:layout_height = "match_parent"
xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:tools = "http://schemas.android.com/tools"
tools:context = ".MainActivity">
<EditText
android:id = "@+id/titleEdtxt"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_marginTop = "30dp"
android:layout_marginRight = "8dp"
android:layout_marginLeft = "6dp"
android:hint = "Title"
android:padding = "16dp"
android:inputType = "text"/>
<EditText
android:id = "@+id/titleDescrptxt"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_marginTop = "120dp"
android:layout_marginRight = "8dp"
android:layout_marginLeft = "6dp"
android:hint = "Description"
android:padding = "16dp"
android:inputType = "textMultiLine|textCapSentences"
android:minHeight = "100dp"
/>
<ImageView
android:id = "@+id/uploadImage"
android:layout_width = "match_parent"
android:layout_height = "370dp"
android:layout_marginStart = "8dp"
android:layout_marginTop = "230dp"
android:layout_marginEnd = "7dp"
android:layout_marginBottom = "7dp" />
<Button
android:id = "@+id/uploadBtn"
android:layout_width = "170dp"
android:layout_height = "wrap_content"
android:layout_marginStart = "8dp"
android:layout_marginTop = "620dp"
android:padding = "16dp"
android:text = "Upload" />
<Button
android:id = "@+id/choose_file_Btn"
android:layout_width = "170dp"
android:layout_height = "wrap_content"
android:layout_marginStart = "220dp"
android:layout_marginTop = "620dp"
android:padding = "16dp"
android:text = "choosefile" />
</RelativeLayout>
Вы используете RelativeLayout, но я не видел свойств типа андроид: layout_below или андроид: layout_above. Из-за этого он создает проблему. Вместо этого вы используете вертикальный LinearLayout, ваша проблема будет решена. Такой android:layout_marginStart = "220dp" android:layout_marginTop = "620dp" стоит. Это не подойдет для других экранных устройств.
да, я поделился ссылкой, так как мое репо низкое, я не могу размещать изображения здесь ... @Arshad
Вы используете много фиксированных размеров, таких как android:layout_marginTop = "620dp", которые на самом деле различаются для разных размеров экрана. Следовательно, вы сталкиваетесь с проблемами. Попробуйте использовать другие более динамичные атрибуты для настройки макета и проверьте его непосредственно в вид дизайна, изменив настройка просмотра телефона (третья) на панели предварительного просмотра..
Проверьте это для справки: -
Note: For better performance and tooling support(to get as in design view), you should instead build your layout with ConstraintLayout.
<?xml version = "1.0" encoding = "utf-8"?>
<ScrollView android:layout_height = "wrap_content"
android:layout_width = "match_parent"
xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:tools = "http://schemas.android.com/tools">
<RelativeLayout android:layout_width = "wrap_content"
android:layout_height = "match_parent"
xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:tools = "http://schemas.android.com/tools"
android:paddingLeft = "8dp"
android:paddingRight = "6dp"
tools:context = ".MainActivity">
<EditText
android:id = "@+id/titleEdtxt"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_marginTop = "30dp"
android:hint = "Title"
android:padding = "16dp"
android:inputType = "text"/>
<EditText
android:id = "@+id/titleDescrptxt"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_below = "@id/titleEdtxt"
android:hint = "Description"
android:padding = "16dp"
android:inputType = "textMultiLine|textCapSentences"
android:minHeight = "100dp"
/>
<ImageView
android:id = "@+id/uploadImage"
android:layout_width = "match_parent"
android:layout_height = "370dp"
android:layout_below = "@id/titleDescrptxt"
android:layout_marginBottom = "7dp" />
<Button
android:id = "@+id/uploadBtn"
android:layout_width = "170dp"
android:layout_height = "wrap_content"
android:layout_marginTop = "10dp"
android:layout_below = "@id/uploadImage"
android:padding = "16dp"
android:text = "Upload" />
<Button
android:id = "@+id/choose_file_Btn"
android:layout_width = "170dp"
android:layout_height = "wrap_content"
android:layout_alignRight = "@id/uploadImage"
android:layout_marginTop = "10dp"
android:layout_below = "@id/uploadImage"
android:padding = "16dp"
android:text = "choosefile" />
</RelativeLayout>
</ScrollView>
Ну, я пробовал все это... но проблема не устранена .. :(
<?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:orientation = "vertical"
tools:context = ".MainActivity">
<RelativeLayout
android:id = "@+id/rr_main_title"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:padding = "20dp">
<EditText
android:id = "@+id/titleEdtxt"
android:layout_width = "match_parent"
android:layout_height = "60dp"
android:hint = "Title"
android:inputType = "text" />
<EditText
android:id = "@+id/titleDescrptxt"
android:layout_width = "match_parent"
android:layout_height = "60dp"
android:layout_below = "@id/titleEdtxt"
android:hint = "Description"
android:inputType = "textMultiLine|textCapSentences" />
</RelativeLayout>
<ImageView
android:src = "@mipmap/ic_launcher"
android:padding = "20dp"
android:id = "@+id/uploadImage"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:layout_above = "@id/ll_submit"
android:layout_below = "@id/rr_main_title" />
<LinearLayout
android:id = "@+id/ll_submit"
android:layout_width = "match_parent"
android:layout_height = "60dp"
android:padding = "5dp"
android:layout_alignParentBottom = "true"
android:layout_marginBottom = "10dp"
android:orientation = "horizontal">
<Button
android:id = "@+id/uploadBtn"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:layout_weight = "1"
android:text = "Upload" />
<Button
android:id = "@+id/choose_file_Btn"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:layout_weight = "1"
android:text = "choosefile" />
</LinearLayout>
</RelativeLayout>
Можете ли вы поделиться дизайном, который вы пытаетесь отобразить, а также кодом активности, где вы используете этот макет?