Я использовал layout_weight в LinearLayout в моем XML-файле. Предварительный просмотр в порядке, но когда я запускаю приложение в телефоне, вид отличается. Это XML-файлВес линейного макета не работает на телефоне, отлично работает в xml-превью в студии android
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<!--<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_dashboard"
android:textSize="25sp"/>-->
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="200dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp">
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:id="@+id/ivBrandImage"
android:scaleType="centerCrop"
android:src="@mipmap/ic_launcher"
android:layout_centerVertical="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:id="@+id/tBrandName"
android:layout_toRightOf="@+id/ivBrandImage"
android:text="Email name"
android:layout_marginLeft="@dimen/margin_left_brand_name"
android:layout_centerVertical="true"/>
<android.support.v7.widget.SwitchCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tBrandName"
android:layout_toRightOf="@+id/ivBrandImage"
android:layout_marginLeft="@dimen/margin_left_brand_name"
android:layout_marginTop="6dp"
android:id="@+id/switchBrand"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_marginTop="@dimen/margin_top_dashboard_card"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:layout_marginLeft="@dimen/margin_left_dashboard"
android:text="@string/textview_pending_approvals"
/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="@dimen/margin_top_dashboard_card"
android:layout_weight="1"
android:layout_gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/margin_left_dashboard"
android:text="@string/textview_pending_approvals"
android:gravity="center_vertical"
/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="@dimen/margin_top_dashboard_card"
android:layout_weight="1"
android:layout_gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/margin_left_dashboard"
android:text="@string/textview_pending_approvals"
android:gravity="center_vertical"
/>
</android.support.v7.widget.CardView>
</LinearLayout>
Ниже приводится XML-просмотр:
А вот фактическое скриншот же по телефону:
Я не могу понять, почему фактический экран отличается от предварительного просмотра xml. Может кто-нибудь, пожалуйста, скажите, в чем тут ошибка?
Как вы надуваете этот xml-макет? –
Это макет чего? Очевидно, что родительский вид вашего 'LinearLayout' имеет свойство android: layout_height =" wrap_content ". Итак, какова иерархия макетов? –
Это один из фрагментов навигационного ящика. Я создал активность ящика навигации из встроенных опций студии. Итак, иерархия несколько похожа: DrawerLayout (activity_main.xml)> CoordinatorLayout (app_bar_main.xml)> CardView (код которого я вставил в вопрос). Все три части находятся в разных xml-файлах. Атрибут «include» используется для включения файлов в иерархию, о которой я упоминал. – backslashN