问题描述
我创建了这个布局,我不知道为什么Button的高度没有填充布局高度
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@color/pf_sm_dividor_light" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" > <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingTop="10dp" android:paddingBottom="10dp" android:layout_toLeftOf="@+id/button"> <ImageView android:id="@+id/li_icon" android:layout_width="24dp" android:layout_height="24dp" android:layout_centerVertical="true" android:src="@drawable/pf_ic_main" android:layout_alignParentLeft="true" android:scaleType="centerInside" android:layout_marginLeft="9dp" android:contentDescription="@string/pf_app_name" /> <TextView style="@style/pf.TextView.sm_title" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:gravity="center_vertical|left" android:layout_marginLeft="2dp" android:text="Text Here" android:layout_toRightOf="@id/li_icon" android:layout_alignRight="@+id/pf_sm_ktext" /> <ir.system.views.KText style="@style/pf.TextView.sm_title" android:layout_width="wrap_content" android:textStyle="normal" android:layout_height="wrap_content" android:gravity="center_vertical|right" android:text="1,500" android:textSize="22sp" android:layout_centerVertical="true" android:layout_alignParentRight="true" android:id="@+id/pf_sm_ktext" /> </RelativeLayout> <!-- Here is the Button --> <Button android:layout_alignParentRight="true" android:layout_width="60dp" android:layout_margin="0dp" android:text="+" android:layout_height="match_parent" android:background="@drawable/pf_btn" android:id="@+id/button" /> </RelativeLayout> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@color/pf_sm_dividor_dark" /> </LinearLayout>
但结果是这样的:
仿真器Android 4.0结果:
推荐答案
您的问题的基本概念..
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end" android:src="@drawable/ic_launcher" /> </LinearLayout>
使用相对布局尝试:
<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" > <ImageView android:id="@+id/li_icon" android:layout_width="24dp" android:layout_height="24dp" android:layout_centerVertical="true" android:layout_alignParentLeft="true" android:scaleType="centerInside" android:layout_marginLeft="9dp" android:src="@drawable/ic_launcher" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:gravity="center_vertical|left" android:layout_marginLeft="2dp" android:text="Text Here" android:layout_toRightOf="@id/li_icon" android:layout_alignRight="@+id/pf_sm_ktext" /> <!-- Here is the Button --> <Button android:layout_alignParentRight="true" android:layout_width="60dp" android:layout_margin="0dp" android:text="+" android:layout_height="wrap_content" android:id="@+id/button" android:layout_toLeftOf="@+id/rl" /> </RelativeLayout>
使用线性布局尝试这个
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:background="@color/red" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" android:layout_gravity="start" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:text="Android Hacker" android:layout_weight="1" android:textSize="15sp" /> <LinearLayout android:layout_width="1dp" android:layout_height="fill_parent" android:background="@color/black" ></LinearLayout> <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:text="okay" android:layout_gravity="end" android:background="@color/brown" /> </LinearLayout>
其他推荐答案
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@android:color/darker_gray" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" > <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_toLeftOf="@+id/button" android:paddingBottom="10dp" android:paddingTop="10dp" > <ImageView android:id="@+id/li_icon" android:layout_width="24dp" android:layout_height="24dp" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:layout_marginLeft="9dp" android:scaleType="centerInside" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignRight="@+id/pf_sm_ktext" android:layout_centerVertical="true" android:layout_marginLeft="2dp" android:layout_toRightOf="@id/li_icon" android:gravity="center_vertical|left" android:text="Text Here" /> <TextView android:id="@+id/pf_sm_ktext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:gravity="center_vertical|right" android:text="1,500" android:textSize="22sp" android:textStyle="normal" /> </RelativeLayout> <!-- Here is the Button --> <Button android:id="@+id/button" android:layout_width="60dp" android:layout_height="match_parent" android:layout_alignParentRight="true" android:layout_margin="0dp" android:background="@android:color/holo_blue_light" android:text="+" /> </RelativeLayout> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@android:color/darker_gray" /> </LinearLayout>
问题描述
I've Created this layout and I don't know why Button's height not filling the layout height
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@color/pf_sm_dividor_light" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" > <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingTop="10dp" android:paddingBottom="10dp" android:layout_toLeftOf="@+id/button"> <ImageView android:id="@+id/li_icon" android:layout_width="24dp" android:layout_height="24dp" android:layout_centerVertical="true" android:src="@drawable/pf_ic_main" android:layout_alignParentLeft="true" android:scaleType="centerInside" android:layout_marginLeft="9dp" android:contentDescription="@string/pf_app_name" /> <TextView style="@style/pf.TextView.sm_title" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:gravity="center_vertical|left" android:layout_marginLeft="2dp" android:text="Text Here" android:layout_toRightOf="@id/li_icon" android:layout_alignRight="@+id/pf_sm_ktext" /> <ir.system.views.KText style="@style/pf.TextView.sm_title" android:layout_width="wrap_content" android:textStyle="normal" android:layout_height="wrap_content" android:gravity="center_vertical|right" android:text="1,500" android:textSize="22sp" android:layout_centerVertical="true" android:layout_alignParentRight="true" android:id="@+id/pf_sm_ktext" /> </RelativeLayout> <!-- Here is the Button --> <Button android:layout_alignParentRight="true" android:layout_width="60dp" android:layout_margin="0dp" android:text="+" android:layout_height="match_parent" android:background="@drawable/pf_btn" android:id="@+id/button" /> </RelativeLayout> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@color/pf_sm_dividor_dark" /> </LinearLayout>
but result is something like this :
emulator android 4.0 result:
推荐答案
Basic concept for your problem ..
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end" android:src="@drawable/ic_launcher" /> </LinearLayout>
Using Relative layout try this :
<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" > <ImageView android:id="@+id/li_icon" android:layout_width="24dp" android:layout_height="24dp" android:layout_centerVertical="true" android:layout_alignParentLeft="true" android:scaleType="centerInside" android:layout_marginLeft="9dp" android:src="@drawable/ic_launcher" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:gravity="center_vertical|left" android:layout_marginLeft="2dp" android:text="Text Here" android:layout_toRightOf="@id/li_icon" android:layout_alignRight="@+id/pf_sm_ktext" /> <!-- Here is the Button --> <Button android:layout_alignParentRight="true" android:layout_width="60dp" android:layout_margin="0dp" android:text="+" android:layout_height="wrap_content" android:id="@+id/button" android:layout_toLeftOf="@+id/rl" /> </RelativeLayout>
Using Linear Layout try this
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:background="@color/red" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" android:layout_gravity="start" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:text="Android Hacker" android:layout_weight="1" android:textSize="15sp" /> <LinearLayout android:layout_width="1dp" android:layout_height="fill_parent" android:background="@color/black" ></LinearLayout> <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:text="okay" android:layout_gravity="end" android:background="@color/brown" /> </LinearLayout>
其他推荐答案
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@android:color/darker_gray" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" > <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_toLeftOf="@+id/button" android:paddingBottom="10dp" android:paddingTop="10dp" > <ImageView android:id="@+id/li_icon" android:layout_width="24dp" android:layout_height="24dp" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:layout_marginLeft="9dp" android:scaleType="centerInside" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignRight="@+id/pf_sm_ktext" android:layout_centerVertical="true" android:layout_marginLeft="2dp" android:layout_toRightOf="@id/li_icon" android:gravity="center_vertical|left" android:text="Text Here" /> <TextView android:id="@+id/pf_sm_ktext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:gravity="center_vertical|right" android:text="1,500" android:textSize="22sp" android:textStyle="normal" /> </RelativeLayout> <!-- Here is the Button --> <Button android:id="@+id/button" android:layout_width="60dp" android:layout_height="match_parent" android:layout_alignParentRight="true" android:layout_margin="0dp" android:background="@android:color/holo_blue_light" android:text="+" /> </RelativeLayout> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@android:color/darker_gray" /> </LinearLayout>