将线性布局与 TextInputLayout 一起使用但遇到问题
Using Linear Layout with TextInputLayout but facing a problem
The image is a screenshot of the fragment in which I have applied the Linear Layout
布局的XML文件如下
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:id="@+id/select_product_image"
android:src="@drawable/ic_image_black_24dp"
/>
<Spinner
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="15dp"
android:id="@+id/category_spinner"
android:layout_marginRight="25dp"
android:layout_marginLeft="25dp"
android:background="@drawable/input_design"
/>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:boxStrokeColor="@color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
app:shapeAppearance="@style/Rounded"
app:endIconMode="clear_text"
>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/product_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/product_name"
android:inputType="text"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:boxStrokeColor="@color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
app:shapeAppearance="@style/Rounded"
app:endIconMode="clear_text"
>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/product_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/product_description"
android:maxLength="100"
android:inputType="text"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:boxStrokeColor="@color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
app:shapeAppearance="@style/Rounded"
app:endIconMode="clear_text"
>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/product_price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/product_price"
android:inputType="numberDecimal"
/>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/add_new_product"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="25dp"
android:layout_marginLeft="25dp"
android:layout_marginTop="15dp"
android:background="@color/colorPrimary"
android:text="@string/add_product"
android:textSize="19dp"
android:textColor="@color/colorAccent"
/>
</LinearLayout>
下面给出了我正在使用的布局文件
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".NavigActivity">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAccent">
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottom_app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:backgroundTint="@color/colorAccent"
app:navigationIcon="@drawable/ic_menu_black_24dp"
app:menu="@menu/menu"
app:buttonGravity="center_vertical"
app:itemIconTint="@drawable/selector"
/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add_black_24dp"
app:layout_anchor="@id/bottom_app_bar"
android:backgroundTint="@color/colorPrimary"
app:maxImageSize="35dp"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/content_frame"
/>
</RelativeLayout>
我已经设置了 LinearLayout 垂直的方向,但它工作不正常。我希望每个属性都在另一个下方并位于中心(水平)。任何形式的帮助将不胜感激
将框架布局宽度从 wrap_content 更改为 match_parent
使用此布局:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".NavigActivity">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAccent">
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottom_app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:backgroundTint="@color/colorAccent"
app:navigationIcon="@drawable/ic_menu_black_24dp"
app:menu="@menu/menu"
app:buttonGravity="center_vertical"
app:itemIconTint="@drawable/selector"
/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add_black_24dp"
app:layout_anchor="@id/bottom_app_bar"
android:backgroundTint="@color/colorPrimary"
app:maxImageSize="35dp"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/content_frame"
/>
</RelativeLayout>
The image is a screenshot of the fragment in which I have applied the Linear Layout
布局的XML文件如下
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:id="@+id/select_product_image"
android:src="@drawable/ic_image_black_24dp"
/>
<Spinner
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="15dp"
android:id="@+id/category_spinner"
android:layout_marginRight="25dp"
android:layout_marginLeft="25dp"
android:background="@drawable/input_design"
/>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:boxStrokeColor="@color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
app:shapeAppearance="@style/Rounded"
app:endIconMode="clear_text"
>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/product_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/product_name"
android:inputType="text"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:boxStrokeColor="@color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
app:shapeAppearance="@style/Rounded"
app:endIconMode="clear_text"
>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/product_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/product_description"
android:maxLength="100"
android:inputType="text"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:boxStrokeColor="@color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
app:shapeAppearance="@style/Rounded"
app:endIconMode="clear_text"
>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/product_price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/product_price"
android:inputType="numberDecimal"
/>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/add_new_product"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="25dp"
android:layout_marginLeft="25dp"
android:layout_marginTop="15dp"
android:background="@color/colorPrimary"
android:text="@string/add_product"
android:textSize="19dp"
android:textColor="@color/colorAccent"
/>
</LinearLayout>
下面给出了我正在使用的布局文件
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".NavigActivity">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAccent">
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottom_app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:backgroundTint="@color/colorAccent"
app:navigationIcon="@drawable/ic_menu_black_24dp"
app:menu="@menu/menu"
app:buttonGravity="center_vertical"
app:itemIconTint="@drawable/selector"
/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add_black_24dp"
app:layout_anchor="@id/bottom_app_bar"
android:backgroundTint="@color/colorPrimary"
app:maxImageSize="35dp"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/content_frame"
/>
</RelativeLayout>
我已经设置了 LinearLayout 垂直的方向,但它工作不正常。我希望每个属性都在另一个下方并位于中心(水平)。任何形式的帮助将不胜感激
将框架布局宽度从 wrap_content 更改为 match_parent
使用此布局:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".NavigActivity">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAccent">
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottom_app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:backgroundTint="@color/colorAccent"
app:navigationIcon="@drawable/ic_menu_black_24dp"
app:menu="@menu/menu"
app:buttonGravity="center_vertical"
app:itemIconTint="@drawable/selector"
/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add_black_24dp"
app:layout_anchor="@id/bottom_app_bar"
android:backgroundTint="@color/colorPrimary"
app:maxImageSize="35dp"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/content_frame"
/>
</RelativeLayout>