在布局Android的按钮高度不填充母 [英] Android Button Height in Layout not filling the parent

查看:157
本文介绍了在布局Android的按钮高度不填充母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建这个布局,我不知道为什么按钮的高度不填充布局高度

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 :

模拟器Android 4.0的结果是:

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>

这篇关于在布局Android的按钮高度不填充母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆