所以,我用XML格式化了这个布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/product_grid_product"
android:orientation="vertical"
android:layout_width="315dp"
android:layout_height="295dp"
android:background="@color/white"
android:contentDescription="@string/image_content_description" >
<LinearLayout
android:id="@+id/product_content"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp">
<LinearLayout
android:id="@+id/product_content_buttons_image"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="130dp" >
<LinearLayout
android:id="@+id/product_content_buttons"
android:orientation="vertical"
android:layout_width="30dp"
android:layout_height="match_parent" >
<ImageButton
android:id="@+id/button_discount"
android:layout_width="30dp"
android:layout_height="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="@color/product_discount_gray"
android:src="@drawable/product_discount" />
<ImageButton
android:id="@+id/button_promotion"
android:layout_width="30dp"
android:layout_height="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="@color/product_promotion_gray"
android:src="@drawable/product_promotion" />
<ImageButton
android:id="@+id/button_oportunity"
android:layout_width="30dp"
android:layout_height="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="@color/product_oportunity_gray"
android:src="@drawable/product_oportinity" />
<ImageButton
android:id="@+id/button_new"
android:layout_width="30dp"
android:layout_height="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="@color/product_new_gray"
android:src="@drawable/product_new" />
</LinearLayout>
<LinearLayout
android:id="@+id/product_content_image_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/product_content_image"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/product_content_details"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView android:id="@+id/product_content_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textStyle="bold"
android:textColor="@color/gray_text"
android:textSize="14sp"
android:text="Panela de Pressão" />
<TextView android:id="@+id/product_content_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/gray_text"
android:textSize="12sp"
android:text="Aço Inox, 1.5L" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView android:id="@+id/product_content_brand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:textStyle="bold"
android:textColor="@color/gray_text"
android:textSize="14sp"
android:text="Marca" />
<TextView android:id="@+id/product_content_price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:gravity="right"
android:textStyle="bold"
android:textColor="@color/gray_text"
android:textSize="16sp"
android:text="10000,00€" />
</LinearLayout>
<!-- starting here -->
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/product_content_ref"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:textStyle="bold"
android:textColor="@color/gray_text"
android:textSize="14sp"
android:text="Ref.: 56065196968" />
<TextView android:id="@+id/product_content_stock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:gravity="right"
android:textStyle="bold"
android:textColor="@color/gray_text"
android:textSize="14sp"
android:text="Stock [240]" />
</LinearLayout>
<!-- to here -->
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/gray_lines"/>
<LinearLayout
android:id="@+id/product_buttons"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="45dp" >
<ImageButton
android:id="@+id/shopping_cart"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="@color/white"
android:src="@drawable/shopping_cart" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/gray_lines"/>
<ImageButton
android:id="@+id/remove_button"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="@color/white"
android:src="@drawable/remove" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/gray_lines"/>
<EditText
android:id="@+id/edit_quantity"
android:layout_width="50dp"
android:layout_height="match_parent"
android:singleLine = "true"
android:background="@color/white"
android:hint="0"
android:gravity="center"
android:textSize="35sp" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/gray_lines"/>
<ImageButton
android:id="@+id/add_button"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="@color/white"
android:src="@drawable/add" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/gray_lines"/>
<Button
android:id="@+id/observations_button"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="@color/white"
android:text="OBS."
android:textSize="25sp"
android:textColor="@color/gray_text" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/gray_lines"/>
</LinearLayout>
没关系带有编码的琴弦,它们是用于虚拟目的的。 问题是我在两条评论(“从这里开始”到“到这里”)之间写的任何内容都没有显示出来。
我已尝试增加布局的高度但不起作用。
请帮忙吗?
答案 0 :(得分:2)
问题是你有两个LinearLayout都有android:layout_height="match_parent"
,所以第一个占据了所有位置。
您应该将android:layout_height
设置为"wrap_content"
或固定值。
答案 1 :(得分:0)
看起来您在层次结构的同一级别上出现了与另一个LinearLayout
不同的LinearLayout
。两者都设置为match_parent
,第一个正在消耗视图区域。
尝试将它们设置为fill_parent
或wrap_content
。