2016-02-01 17 views
1

我目前有一个问题,其中布局如下所示重叠海誓山盟。 enter image description here停止线性布局重叠

从来没有这个问题,因为似乎无法找到问题的原因。 文本当前正确定位,但似乎两个线性布局不正确加权。

XML

<?xml version="1.0" encoding="utf-8"?> 

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/card_view" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    card_view:cardBackgroundColor="#777777" 
    card_view:cardCornerRadius="0dp" 
    card_view:cardElevation="3dp" 
    card_view:cardUseCompatPadding="true"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:gravity="center_vertical|center_horizontal" 
     android:orientation="horizontal" 
     android:weightSum="10"> 

     <LinearLayout 
      android:layout_width="0dip" 
      android:layout_height="match_parent" 
      android:layout_weight="3"> 

      <ImageView 
       android:id="@+id/thumbImageView" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@drawable/soul_bg" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="0dip" 
      android:layout_height="match_parent" 
      android:layout_weight="7"> 

      <TableLayout 
       android:id="@+id/tableLayout" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:stretchColumns="0,1,2" 
       android:weightSum="6"> 

       <TableRow 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:layout_weight="3" 
        android:textColor="#FFF" 
        android:weightSum="3"> 

        <TextView 
         android:id="@+id/nameTextView" 
         android:layout_width="0dp" 
         android:layout_height="match_parent" 
         android:layout_weight="1" 
         android:text="Name:" 
         android:textColor="#FFF" /> 

        <TextView 
         android:id="@+id/hpTextView" 
         android:layout_width="0dp" 
         android:layout_height="match_parent" 
         android:layout_weight="1" 
         android:text="HP:" 
         android:textColor="#FFF" /> 

        <TextView 
         android:id="@+id/atkTextView" 
         android:layout_width="0dp" 
         android:layout_height="match_parent" 
         android:layout_weight="1" 
         android:text="ATK:" 
         android:textColor="#FFF" /> 
       </TableRow> 

       <TableRow 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:layout_weight="3" 
        android:textColor="#FFF" 
        android:weightSum="3"> 

        <TextView 
         android:id="@+id/typeTextView" 
         android:layout_width="0dp" 
         android:layout_height="match_parent" 
         android:layout_weight="1" 
         android:text="Race:" 
         android:textColor="#FFF" /> 

        <TextView 
         android:id="@+id/defTextView" 
         android:layout_width="0dp" 
         android:layout_height="match_parent" 
         android:layout_weight="1" 
         android:text="DEF" 
         android:textColor="#FFF" /> 

        <TextView 
         android:id="@+id/wisTextView" 
         android:layout_width="0dp" 
         android:layout_height="match_parent" 
         android:layout_weight="1" 
         android:text="WIS" 
         android:textColor="#FFF" /> 
       </TableRow> 
      </TableLayout> 
     </LinearLayout> 
    </LinearLayout> 
</android.support.v7.widget.CardView> 

回答

1

您发布的布局,是非常正确的。 这是它如何找我: enter image description here

这里看起来不像XML的问题。

我只能猜测,究竟是什么出了问题你,但同样的效果可以存档,如果设置CardView的宽度wrap_content(&如果它不是在布局为CardView足够的空间),所以要当然,你不会在代码背后的某个地方做它。因此,请在代码中查找的任何内容,这可能会更改CardView或其子项的布局属性。

此外,我建议确保您使用最新的CardView支持库。

P.S.

您仍然可以略微提高你的布局有点通过删除不必要的组件出来的:

<android.support.v7.widget.CardView 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/card_view" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    card_view:cardBackgroundColor="#777777" 
    card_view:cardCornerRadius="0dp" 
    card_view:cardElevation="3dp" 
    card_view:cardUseCompatPadding="true"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="10"> 

     <ImageView 
      android:id="@+id/thumbImageView" 
      android:layout_width="0dp" 
      android:layout_weight="3" 
      android:layout_height="match_parent"/> 
     <TableLayout 
      android:id="@+id/tableLayout" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:stretchColumns="0,1,2" 
      android:layout_weight="7" 
      android:weightSum="6"> 

      <TableRow 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_weight="3" 
       android:textColor="#FFF" 
       android:weightSum="3"> 
       <TextView 
        android:id="@+id/nameTextView" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:text="Name:" 
        android:textColor="#FFF" /> 
       <TextView 
        android:id="@+id/hpTextView" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:text="HP:" 
        android:textColor="#FFF" /> 
       <TextView 
        android:id="@+id/atkTextView" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:text="ATK:" 
        android:textColor="#FFF" /> 
      </TableRow> 

      <TableRow 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_weight="3" 
       android:textColor="#FFF" 
       android:weightSum="3"> 
       <TextView 
        android:id="@+id/typeTextView" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:text="Race:" 
        android:textColor="#FFF" /> 
       <TextView 
        android:id="@+id/defTextView" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:text="DEF" 
        android:textColor="#FFF" /> 
       <TextView 
        android:id="@+id/wisTextView" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:text="WIS" 
        android:textColor="#FFF" /> 
      </TableRow> 
     </TableLayout> 
    </LinearLayout> 
</android.support.v7.widget.CardView> 

我希望,它有助于

0

如果您有重叠的比你可以使用属性的问题修复的ImageView

android:scaleType="fitXY" 

建议 ::你必须做出不同的尺寸您在不同设备上进行测试时的图像。

所以你的布局将如下

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/card_view" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    card_view:cardBackgroundColor="#777777" 
    card_view:cardCornerRadius="0dp" 
    card_view:cardElevation="3dp" 
    card_view:cardUseCompatPadding="true"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="10"> 

     <ImageView 
      android:id="@+id/thumbImageView" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="3" 
      android:background="@drawable/soul_bg" 
      android:scaleType="fitXY" /> 

     <TableLayout 
      android:id="@+id/tableLayout" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="7" 
      android:stretchColumns="0,1,2" 
      android:weightSum="6"> 

      <TableRow 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_weight="3" 
       android:textColor="#FFF" 
       android:weightSum="3"> 

       <TextView 
        android:id="@+id/nameTextView" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:text="Name:" 
        android:textColor="#FFF" /> 

       <TextView 
        android:id="@+id/hpTextView" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:text="HP:" 
        android:textColor="#FFF" /> 

       <TextView 
        android:id="@+id/atkTextView" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:text="ATK:" 
        android:textColor="#FFF" /> 
      </TableRow> 

      <TableRow 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_weight="3" 
       android:textColor="#FFF" 
       android:weightSum="3"> 

       <TextView 
        android:id="@+id/typeTextView" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:text="Race:" 
        android:textColor="#FFF" /> 

       <TextView 
        android:id="@+id/defTextView" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:text="DEF" 
        android:textColor="#FFF" /> 

       <TextView 
        android:id="@+id/wisTextView" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:text="WIS" 
        android:textColor="#FFF" /> 
      </TableRow> 
     </TableLayout> 
    </LinearLayout> 
</android.support.v7.widget.CardView> 
+0

是你的问题解决了吗? @ M0rty –