Android Button Height in Layout not filling the parent

前端 未结 2 451
[愿得一人]
[愿得一人] 2021-01-07 13:30

I\'ve Created this layout and I don\'t know why Button\'s height not filling the layout height


         


        
相关标签:
2条回答
  • 2021-01-07 14:13

    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>
    

    enter image description here

    0 讨论(0)
  • 2021-01-07 14:19
    <?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>
    
    0 讨论(0)
提交回复
热议问题