llx2007
凌云志轩
采纳率89%
2015-04-17 03:49 阅读 3.0k

android adapter设置高度

我的item.xml文件里是1个LinearLayout (a),里面9个LinearLayout(b)
main.xml里面一个gridview,一行一个item,我想的是每个b按比例显示大小(就是等高)。怎么实现(不能固定死呀,要每个手机上显示b的高度都一样)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

3条回答 默认 最新

  • 已采纳
    danielinbiti danielinbiti 2015-04-17 04:19
     <LinearLayout  
        xmlns:android="http://schemas.android.com/apk/res/android"  
        android:orientation="vertical"   
        android:layout_width="match_parent"  
        android:layout_height="match_parent">
            <LinearLayout  
        android:orientation="vertical"   
        android:layout_width="match_parent"  
            android:layout_weight='1'
        android:layout_height="wrap_content">
       </LinearLayout>
         <LinearLayout  
        android:orientation="vertical"   
        android:layout_width="match_parent"  
            android:layout_weight='1'  //关键是设置权重一样就行,就是等高
        android:layout_height="wrap_content">
       </LinearLayout>
         。。。总共9个
    <LinearLayout/>
    
    点赞 1 评论 复制链接分享
  • llx2007 凌云志轩 2015-04-17 04:49

    Myadapter.java

     public class MyAdapter extends BaseAdapter {
        private LayoutInflater inflater;
        private Context mcontext;
    
        private Integer[] mThumbnails = {R.drawable.yu_bj_unpress9};
        public MyAdapter( Context c)
        {
            mcontext = c;
        }
        public int getCount() {
            return mThumbnails.length;
        }
        public Object getItem(int position) {
            return null;
        }
    
        public long getItemId(int position) {
            return 0;
        }
    
        @SuppressLint({ "InflateParams", "ViewHolder" })
        public View getView(int position, View grid, ViewGroup parent)
        {
            grid =LayoutInflater.from(mcontext).inflate(R.layout.dev_list_item_9,null);
    
            AbsListView.LayoutParams params = new AbsListView.LayoutParams(
                    ViewGroup.LayoutParams.FILL_PARENT, 408
            );
            grid.setLayoutParams(params);
    
    
            return grid;
        }
    
    
    }
    
    
    点赞 评论 复制链接分享
  • llx2007 凌云志轩 2015-04-17 07:15

    item_9.xml

     <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:gravity="center_horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:id="@+id/dev_list_item_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/yu_bj_unpress9"
            android:orientation="vertical">
    
            <LinearLayout
                android:id = "@+id/dev_head"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:layout_marginRight="10dp"
                android:layout_marginLeft="10dp">
                <TextView
                    android:id="@+id/dev_id"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="0.25"
                    android:gravity="center_vertical"
                    android:layout_marginLeft="5dp"
                    android:layout_marginRight="5dp"
                    android:drawableRight="@drawable/offline1"
                    android:drawablePadding="20dp"
                    android:textColor = "#f3f3f3"
                    android:singleLine="true"
                    android:text="加载中..."
                    android:layout_marginTop="0dp"
                    android:layout_marginBottom="0dp" />
                <ImageView
                    android:id="@+id/record_op"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_vertical"
                    android:layout_weight="1.2"
                    android:src="@drawable/off"
                    android:layout_marginRight="5dp"
                    android:layout_marginBottom="5dp"
                    android:layout_marginTop="5dp" />
    
            </LinearLayout>
    
            <LinearLayout
                android:id="@+id/dev_air01humidity_lout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:layout_marginLeft="10dp"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:layout_marginRight="10dp">
                <ImageView
                    android:id="@+id/dev_do_img"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/yu"
                    android:layout_marginTop="5dp"
                    android:layout_marginBottom="5dp" />
                <TextView
                    android:id="@+id/dev_air01humidity_view"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp"
                    android:text="空气湿度: "
                    android:textColor = "#f3f3f3" />
                <ProgressBar
                    android:id="@+id/dev_air01humidity_bar"
                    android:layout_width="match_parent"
                    android:layout_height="12dp"
                    android:layout_weight="1.5"
                    style="@style/progressbarStyle_Horizontal_Yellow"
                    android:layout_marginRight="2dp"
                    android:max="100"
                    android:progress="50"  />
                <!-- style="?android:attr/progressBarStyleHorizontal" -->
                <TextView
                    android:id="@+id/dev_air01humidity"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="2"
                    android:layout_marginRight="15dp"
                    android:singleLine="true"
                    android:textColor = "#f3f3f3"
                    android:text="加载中..." />
            </LinearLayout>
    
            <LinearLayout
                android:id="@+id/dev_air02humidity_lout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:layout_marginLeft="10dp"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:layout_marginRight="10dp">
                <ImageView
                    android:id="@+id/dev_air02humidity_img"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/tmp"
                    android:layout_marginTop="5dp"
                    android:layout_marginBottom="5dp" />
                <TextView
                    android:id="@+id/dev_air02humidity_view"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp"
                    android:text="空气湿度: "
                    android:textColor = "#f3f3f3" />
                <ProgressBar
                    android:id="@+id/dev_air02humidity_bar"
                    android:layout_width="match_parent"
                    android:layout_height="12dp"
                    android:layout_weight="1.5"
                    style="@style/progressbarStyle_Horizontal_Yellow"
                    android:layout_marginRight="2dp"
                    android:max="100"
                    android:progress="50"  />
                <!-- style="?android:attr/progressBarStyleHorizontal" -->
                <TextView
                    android:id="@+id/dev_air02humidity"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="2"
                    android:layout_marginRight="15dp"
                    android:singleLine="true"
                    android:textColor = "#f3f3f3"
                    android:text="加载中..." />
            </LinearLayout>
    
            <LinearLayout
                android:id="@+id/dev_soil01humidity_lout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:layout_marginLeft="10dp"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:layout_marginRight="10dp">
                <ImageView
                    android:id="@+id/dev_soil01humidity_img"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/tmp"
                    android:layout_marginTop="5dp"
                    android:layout_marginBottom="5dp" />
                <TextView
                    android:id="@+id/dev_soil01humidity_view"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp"
                    android:text="土壤湿度: "
                    android:textColor = "#f3f3f3" />
                <ProgressBar
                    android:id="@+id/dev_soil01humidity_bar"
                    android:layout_width="match_parent"
                    android:layout_height="12dp"
                    android:layout_weight="1.5"
                    style="@style/progressbarStyle_Horizontal_Yellow"
                    android:layout_marginRight="2dp"
                    android:max="100"
                    android:progress="50"  />
                <!-- style="?android:attr/progressBarStyleHorizontal" -->
                <TextView
                    android:id="@+id/dev_soil01humidity"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="2"
                    android:layout_marginRight="15dp"
                    android:singleLine="true"
                    android:textColor = "#f3f3f3"
                    android:text="加载中..." />
            </LinearLayout>
            <!-- android:drawableRight="@drawable/shang" -->
            <LinearLayout
                android:id="@+id/dev_soil02humidity_lout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:layout_marginLeft="10dp"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:layout_marginRight="10dp">
                <ImageView
                    android:id="@+id/dev_soil02humidity_img"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/tmp"
                    android:layout_marginTop="5dp"
                    android:layout_marginBottom="5dp" />
                <TextView
                    android:id="@+id/dev_soil02humidity_view"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp"
                    android:text="土壤湿度: "
                    android:textColor = "#f3f3f3" />
                <ProgressBar
                    android:id="@+id/dev_soil02humidity_bar"
                    android:layout_width="match_parent"
                    android:layout_height="12dp"
                    android:layout_weight="1.5"
                    style="@style/progressbarStyle_Horizontal_Yellow"
                    android:layout_marginRight="2dp"
                    android:max="100"
                    android:progress="50"  />
                <!-- style="?android:attr/progressBarStyleHorizontal" -->
                <TextView
                    android:id="@+id/dev_soil02humidity"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="2"
                    android:layout_marginRight="15dp"
                    android:singleLine="true"
                    android:textColor = "#f3f3f3"
                    android:text="加载中..." />
            </LinearLayout>
            <LinearLayout
                android:id="@+id/dev_co2_lout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:layout_marginLeft="10dp"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:layout_marginRight="10dp">
                <ImageView
                    android:id="@+id/dev_co2_img"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/tmp"
                    android:layout_marginTop="5dp"
                    android:layout_marginBottom="5dp" />
                <TextView
                    android:id="@+id/dev_c02humidity_view"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp"
                    android:text="二氧化碳: "
                    android:textColor = "#f3f3f3" />
                <ProgressBar
                    android:id="@+id/dev_c02_bar"
                    android:layout_width="match_parent"
                    android:layout_height="12dp"
                    android:layout_weight="1.5"
                    style="@style/progressbarStyle_Horizontal_Yellow"
                    android:layout_marginRight="2dp"
                    android:max="100"
                    android:progress="50"  />
                <!-- style="?android:attr/progressBarStyleHorizontal" -->
                <TextView
                    android:id="@+id/dev_co2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="2"
                    android:layout_marginRight="15dp"
                    android:singleLine="true"
                    android:textColor = "#f3f3f3"
                    android:text="加载中..." />
            </LinearLayout>
            <LinearLayout
                android:id="@+id/dev_1_lout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:layout_marginLeft="10dp"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:layout_marginRight="10dp">
                <ImageView
                    android:id="@+id/dev_1_img"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/tmp"
                    android:layout_marginTop="5dp"
                    android:layout_marginBottom="5dp" />
                <TextView
                    android:id="@+id/dev_1_view"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp"
                    android:text="土壤湿度: "
                    android:textColor = "#f3f3f3" />
                <ProgressBar
                    android:id="@+id/dev_1_bar"
                    android:layout_width="match_parent"
                    android:layout_height="12dp"
                    android:layout_weight="1.5"
                    style="@style/progressbarStyle_Horizontal_Yellow"
                    android:layout_marginRight="2dp"
                    android:max="100"
                    android:progress="50"  />
                <!-- style="?android:attr/progressBarStyleHorizontal" -->
                <TextView
                    android:id="@+id/dev_1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="2"
                    android:layout_marginRight="15dp"
                    android:singleLine="true"
                    android:textColor = "#f3f3f3"
                    android:text="加载中..." />
            </LinearLayout>
            <!-- android:drawableRight="@drawable/xia" -->
    
            <LinearLayout
                android:id="@+id/dev_ph_lout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:layout_marginLeft="10dp"
                android:visibility="gone"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:layout_marginRight="10dp">
                <ImageView
                    android:id="@+id/dev_ph_img"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/tmp"
                    />
                <TextView
                    android:id="@+id/dev_ph_view"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp"
                    android:text="PH   : "
                    android:textColor = "#f3f3f3" />
                <ProgressBar
                    android:id="@+id/dev_ph_bar"
                    android:layout_width="match_parent"
                    android:layout_height="12dp"
                    android:layout_weight="1.5"
                    style="@style/progressbarStyle_Horizontal_Yellow"
                    android:layout_marginRight="2dp"
                    android:max="100"
                    android:progress="50"  />
                <!-- style="?android:attr/progressBarStyleHorizontal" -->
                <TextView
                    android:id="@+id/dev_ph"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1.8"
                    android:layout_marginRight="15dp"
                    android:singleLine="true"
                    android:textColor = "#f3f3f3"
                    android:text="加载中..." /></LinearLayout>
    
    
    
    
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1.8"
                android:orientation="horizontal">
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical" >
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:layout_marginLeft="10dp"
                        android:gravity="center_vertical" >
                        <TextView
                            android:id="@+id/dev_ctrl_stat_sig_title"
                            android:layout_width="wrap_content"
                            android:layout_height="match_parent"
                            android:layout_marginRight="5dp"
                            android:gravity="center_vertical"
                            android:visibility="gone"
                            android:text="接触开关状态: "
                            android:textColor="#f3f3f3" />
                        <ImageView
                            android:id="@+id/dev_ctrl_stat_img"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/aerator_offline"
                            android:layout_marginBottom="5dp"
                            android:layout_marginTop="5dp" />
                        <ImageView
                            android:id="@+id/dev_ctrl_stat_img2"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/aerator_offline"
                            android:visibility="gone"
                            android:layout_marginLeft="10dp"/>
                        <ImageView
                            android:id="@+id/dev_ctrl_stat_img3"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/aerator_offline"
                            android:visibility="gone"
                            android:layout_marginLeft="10dp"/>
                        <ImageView
                            android:id="@+id/dev_ctrl_stat_img4"
                            android:layout_width="wrap_content"
                            android:layout_height="match_parent"
                            android:src="@drawable/aerator_offline"
                            android:visibility="gone"
                            android:layout_marginLeft="10dp"/>
                        <ImageView
                            android:id="@+id/dev_ctrl_stat_img5"
                            android:layout_width="wrap_content"
                            android:layout_height="match_parent"
                            android:src="@drawable/aerator_offline"
                            android:visibility="gone"
                            android:layout_marginLeft="10dp"/>
                        <ImageView
                            android:id="@+id/dev_ctrl_stat_img6"
                            android:layout_width="wrap_content"
                            android:layout_height="match_parent"
                            android:src="@drawable/aerator_offline"
                            android:visibility="gone"
                            android:layout_marginLeft="10dp"/>
                        <TextView
                            android:id="@+id/dev_ctrl_stat_title"
                            android:layout_width="wrap_content"
                            android:layout_height="match_parent"
                            android:layout_marginLeft="5dp"
                            android:gravity="center_vertical"
                            android:text="接触开关状态: "
    
                            android:textColor="#f3f3f3" />
                        <TextView
                            android:id="@+id/dev_ctrl_stat_text"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:gravity="center_vertical"
                            android:singleLine="true"
                            android:layout_weight="1"
                            android:textColor = "#f3f3f3"
                            android:text="加载中..."
                            />
                        <!-- <TextView
                            android:id="@+id/event_cha"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:gravity="center"
                            android:singleLine="true"
                            android:textColor = "#f3f3f3"
                            android:text="事件查询>>" /> -->
                        <!-- <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_weight="1.3" >
                            <ImageView
                                android:id="@+id/event_cha"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_gravity="center"
                                android:src="@drawable/event_btn" />
                        </LinearLayout> -->
    
                    </LinearLayout>
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:layout_marginLeft="10dp"
                        android:gravity="center_vertical" >
                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/time_stat"
                            android:layout_marginTop="5dp"
                            android:layout_marginBottom="5dp" />
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="match_parent"
                            android:layout_marginLeft="5dp"
                            android:gravity="center_vertical"
                            android:text="更新时间: "
                            android:textColor="#f3f3f3" />
                        <TextView
                            android:id="@+id/dev_stat"
                            android:layout_width="wrap_content"
                            android:layout_height="match_parent"
                            android:gravity="center_vertical"
                            android:singleLine="true"
                            android:text="加载中..."
                            android:textColor="#f3f3f3" />
    
                    </LinearLayout>
                </LinearLayout>
    
    
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="4.5" >
                    <!-- ImageView
                        android:id="@+id/event_cha"
                        android:layout_width="0dp"
                        android:layout_height="0dp" />-->
                    <ImageView
                        android:id="@+id/event_his_qry"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:src="@drawable/event_btn"
                        android:layout_marginRight="10dp"
                        android:layout_marginTop="10dp"
                        android:layout_marginBottom="10dp" />
                </LinearLayout>
    
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
    

    main.xml

     <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/body_bj"
                    android:layout_weight="1.5"
                    android:layout_marginLeft="0dp"
                    android:layout_marginRight="0dp"
                    android:layout_marginBottom="0dp"
                    android:layout_marginTop="0dp"  >
                    <!-- android:background="@drawable/bj_qn"
                    android:layout_marginLeft="2dp"
                    android:layout_marginRight="2dp"
                    android:layout_marginBottom="5dp"
                    android:layout_marginTop="2dp" -->
    
                    <GridView
                        android:id="@+id/dev_list"
                        android:numColumns="1"
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:verticalSpacing="0dp"
                        android:horizontalSpacing="0dp"
                        android:stretchMode="columnWidth" />
                </LinearLayout>
    

    现在都做了放大了,本来高度在2/3的成了满屏了,怎么办?

    点赞 评论 复制链接分享

相关推荐