zoukankan      html  css  js  c++  java
  • BaseAdapter中使用固定好的xml文件无法自适应大小

    例如我在xml中定义了这个东西

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     3     android:id="@+id/viewElement"
     4     android:layout_width="match_parent"
     5     android:layout_height="wrap_content" >
     6 
     7     <ImageView
     8         android:id="@+id/useImg"
     9         android:layout_width="wrap_content"
    10         android:layout_height="wrap_content"
    11         android:layout_alignParentLeft="true"
    12         android:layout_alignParentTop="true"
    13         android:src="@drawable/ic_launcher" />
    14 
    15     <RelativeLayout
    16         android:id="@+id/viewElmentPath1"
    17         android:layout_width="wrap_content"
    18         android:layout_height="wrap_content"
    19         android:layout_toRightOf="@id/useImg" >
    20 
    21         <TextView
    22             android:id="@+id/timeText"
    23             android:layout_width="wrap_content"
    24             android:layout_height="wrap_content"
    25             android:layout_alignParentRight="true"
    26             android:layout_alignParentTop="true"
    27             android:text="1小时前" />
    28 
    29         <TextView
    30             android:id="@+id/userName"
    31             android:layout_width="wrap_content"
    32             android:layout_height="wrap_content"
    33             android:layout_alignTop="@+id/useImg"
    34             android:text="经典、微小说"
    35             android:textSize="15sp" />
    36 
    37         <TextView
    38             android:id="@+id/weiboText"
    39             android:layout_width="match_parent"
    40             android:layout_height="wrap_content"
    41             android:layout_below="@id/userName"
    42             android:autoLink="all"
    43             android:paddingRight="5dp"
    44             android:text="" />
    45 
    46         <TextView
    47             android:id="@+id/source"
    48             android:layout_width="wrap_content"
    49             android:layout_height="wrap_content"
    50             android:layout_below="@id/weiboText"
    51             android:text="来自:iPad客户端"
    52             android:textSize="10sp" />
    53 
    54         <LinearLayout
    55             android:layout_width="wrap_content"
    56             android:layout_height="wrap_content"
    57             android:layout_alignParentBottom="true"
    58             android:layout_alignParentRight="true"
    59             android:orientation="horizontal" >
    60 
    61             <TextView
    62                 android:id="@+id/repostCount"
    63                 android:layout_width="wrap_content"
    64                 android:layout_height="wrap_content"
    65                 android:paddingRight="5dp"
    66                 android:text="1"
    67                 android:textSize="10sp" />
    68 
    69             <TextView
    70                 android:id="@+id/commentCount"
    71                 android:layout_width="wrap_content"
    72                 android:layout_height="wrap_content"
    73                 android:paddingRight="5dp"
    74                 android:text="73"
    75                 android:textSize="10sp" />
    76         </LinearLayout>
    77     </RelativeLayout>
    78 
    79 </RelativeLayout>

    然后在getView中的代码是

    1 View reLayout2 = (View)LayoutInflater.
    2             from(MainActivity.this).inflate(
    3             R.layout.activity_main,
    4             parent, false);
    5 return reLayout2;

    效果就是这样了,不知道怎么解决这个问题

    最后发现只要把id为source的显示位置改为android:layout_below="@id/weiboText"就可以了

    也就是把现实来源的textview改为id为weiboText的下面而不是容器的左下面

    改完后效果图

  • 相关阅读:
    北航算法作业三
    水库抽样
    python命名空间
    我说
    Fn键
    windows批处理运行java程序
    Java Sound初探
    java.io.IOException: mark/reset not supported
    三层交换机对链路层数据帧的处理
    北航数值分析作业三
  • 原文地址:https://www.cnblogs.com/Jabba93/p/2672366.html
Copyright © 2011-2022 走看看