我必须使用UI测试设计。我在运行时遇到错误。它只是UI。没有功能。我想在水平方向上显示这两个相对布局。
更新 我终于在下面的代码中删除了@ color / tile_text后发现了。它正在发挥作用。我的tile_text.xml出了什么问题?
这是我的代码。
tile_text.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="#01B275" />
<item android:state_enabled="false" android:color="#01B275" />
<item android:color="@color/tile_text" />
</selector>
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp">
<RelativeLayout
android:id="@+id/Relative1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp">
<TextView
android:id="@+id/title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:maxLines="5"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:paddingTop="7dp"
android:text="Title Text"
android:textColor="@color/tile_text"
android:textSize="14sp" />
<TextView
android:id="@+id/my_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title_text"
android:layout_marginBottom="3dp"
android:ellipsize="end"
android:maxLines="1"
android:paddingBottom="7dp"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:text=""
android:textSize="12sp" />
<!-- android:textColor="#9B9BA5" -->
<TextView
android:id="@+id/seperator"
android:layout_width="fill_parent"
android:layout_height="1px"
android:layout_below="@+id/my_text" />
<!-- android:background="#939393" -->
<Button
android:id="@+id/btn_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/seperator"
android:background="@android:color/transparent"
android:drawableRight="@drawable/ic_unsave"
android:minHeight="0dp"
android:minWidth="0dp"
android:paddingBottom="5dp"
android:paddingRight="7dp"
android:paddingTop="5dp" />
<Button
android:id="@+id/btn_like"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/seperator"
android:background="@android:color/transparent"
android:drawableLeft="@drawable/ic_unlike"
android:drawablePadding="5dp"
android:minHeight="0dp"
android:minWidth="0dp"
android:paddingBottom="5dp"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:paddingTop="5dp"
android:text=""
android:textSize="14sp" />
<!-- android:textColor="#01B275"-->
</RelativeLayout>
<RelativeLayout
android:id="@+id/Relative2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp">
<TextView
android:id="@+id/title_text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:maxLines="5"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:paddingTop="7dp"
android:text="Title Text"
android:textColor="@color/tile_text"
android:textSize="14sp" />
<TextView
android:id="@+id/my_text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title_text2"
android:layout_marginBottom="3dp"
android:ellipsize="end"
android:maxLines="1"
android:paddingBottom="7dp"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:text=""
android:textSize="12sp" />
<!-- android:textColor="#9B9BA5" -->
<TextView
android:id="@+id/seperator2"
android:layout_width="fill_parent"
android:layout_height="1px"
android:layout_below="@+id/my_text2" />
<!-- android:background="#939393"-->
<Button
android:id="@+id/btn_save2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/seperator2"
android:background="@android:color/transparent"
android:drawableRight="@drawable/ic_unsave"
android:minHeight="0dp"
android:minWidth="0dp"
android:paddingBottom="5dp"
android:paddingRight="7dp"
android:paddingTop="5dp" />
<Button
android:id="@+id/btn_like2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/seperator2"
android:background="@android:color/transparent"
android:drawableLeft="@drawable/ic_unlike"
android:drawablePadding="5dp"
android:minHeight="0dp"
android:minWidth="0dp"
android:paddingBottom="5dp"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:paddingTop="5dp"
android:text=""
android:textSize="14sp" />
<!-- android:textColor="#01B275" -->
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
日志
07-08 13:49:53.300 22128-22128/com.example.test.sampleapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.StackOverflowError
at android.util.SparseArray.get(SparseArray.java:82)
at android.util.SparseArray.get(SparseArray.java:73)
at android.content.res.StringBlock.get(StringBlock.java:70)
at android.content.res.AssetManager.getResourceValue(AssetManager.java:202)
at android.content.res.Resources.getValue(Resources.java:1114)
at android.content.res.Resources.getColor(Resources.java:800)
at android.content.res.ColorStateList.inflate(ColorStateList.java:224)
at android.content.res.ColorStateList.createFromXmlInner(ColorStateList.java:150)
at android.content.res.ColorStateList.createFromXml(ColorStateList.java:129)
at android.content.res.Resources.loadColorStateList(Resources.java:2243)
at android.content.res.Resources.getColor(Resources.java:812)
at android.content.res.ColorStateList.inflate(ColorStateList.java:224)
at android.content.res.ColorStateList.createFromXmlInner(ColorStateList.java:150)
at android.content.res.ColorStateList.createFromXml(ColorStateList.java:129)
at android.content.res.Resources.loadColorStateList(Resources.java:2243)
at android.content.res.Resources.getColor(Resources.java:812)
at android.content.res.ColorStateList.inflate(ColorStateList.java:224)
at android.content.res.ColorStateList.createFromXmlInner(ColorStateList.java:150)
at android.content.res.ColorStateList.createFromXml(ColorStateList.java:129)
at android.content.res.Resources.loadColorStateList(Resources.java:2243)
at android.content.res.Resources.getColor(Resources.java:812)
at android.content.res.ColorStateList.inflate(ColorStateList.java:224)
at android.content.res.ColorStateList.createFromXmlInner(ColorStateList.java:150)
at android.content.res.ColorStateList.createFromXml(ColorStateList.java:129)
at android.content.res.Resources.loadColorStateList(Resources.java:2243)
at android.content.res.Resources.getColor(Resources.java:812)
at android.content.res.ColorStateList.inflate(ColorStateList.java:224)
at android.content.res.ColorStateList.createFromXmlInner(ColorStateList.java:150)
at android.content.res.ColorStateList.createFromXml(ColorStateList.java:129)
at android.content.res.Resources.loadColorStateList(Resources.java:2243)
at android.content.res.Resources.getColor(Resources.java:812)
at android.content.res.ColorStateList.inflate(ColorStateList.java:224)
at android.content.res.ColorStateList.createFromXmlInner(ColorStateList.java:150)
at android.content.res.ColorStateList.createFromXml(ColorStateList.java:129)
at android.content.res.Resources.loadColorStateList(Resources.java:2243)
at android.content.res.Resources.getColor(Resources.java:812)
at android.content.res.ColorStateList.inflate(ColorStateList.java:224)
at android.content.res.ColorStateList.createFromXmlInner(ColorStateList.java:150)
at android.content.res.ColorStateList.createFromXml(ColorStateList.java:129)
at android.content.res.Resources.loadColorStateList(Resources.java:2243)
at android.content.res.Resources.getColor(Resources.java:812)
at android.content.res.ColorStateList.inflate(ColorStateList.java:224)
at android.content.res.ColorStateList.createFromXmlInner(ColorStateList.java:150)
at android.content.res.ColorStateList.createFromXml(ColorStateList.java:129)
at android.content.res.Resources.loadColorStateList(Resources.java:2243)
at android.content.res.Resources.getColor(Resources.java:812)
at android.content.res.ColorStateList.inflate(ColorStateList.java:224)
at android.content.res.ColorStateList.createFromXmlInner(ColorStateList.java:150)
at android.content.res.ColorStateList.createFromXml(ColorStateList.java:129)
at android.content.res.Resources.loadColorStateList(Resources.java:2243)
at android.content.res.Resources.getColor(Resources.java:812)
at android.content.res.ColorStateList.inflate(ColorStateList.java:224)
at android.content.res.ColorStateList.createFromXmlInner(ColorStateList.java:150)
at android.content.res.ColorStateList.createFromXml(ColorStateList.java:129)
at android.content.res.Resources.loadColorStateList(Resources.java:2243
答案 0 :(得分:0)
添加
android:layout_toRightOf="@+id/Relative1"
到你的第二个布局。
您也可以使用
将父版面切换为LinearLayout
android:orientation="horizontal"
您收到错误,因为以下资源不存在:
@drawable/ic_unsave
@drawable/ic_unlike
@color/tile_text
@color/tile_text
答案 1 :(得分:0)
使用以下代码:
(代码中的细微变化)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp">
<RelativeLayout
android:id="@+id/Relative1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp">
<TextView
android:id="@+id/title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:maxLines="5"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:paddingTop="7dp"
android:text="Title Text"
android:textColor="@color/intouch_green"
android:textSize="14sp" />
<TextView
android:id="@+id/my_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title_text"
android:layout_marginBottom="3dp"
android:ellipsize="end"
android:maxLines="1"
android:paddingBottom="7dp"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:text=""
android:textSize="12sp" />
<!-- android:textColor="#9B9BA5" -->
<TextView
android:id="@+id/seperator"
android:layout_width="fill_parent"
android:layout_height="1px"
android:layout_below="@+id/my_text" />
<!-- android:background="#939393" -->
<Button
android:id="@+id/btn_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/seperator"
android:background="@android:color/transparent"
android:drawableRight="@drawable/feildetails"
android:minHeight="0dp"
android:minWidth="0dp"
android:paddingBottom="5dp"
android:paddingRight="7dp"
android:paddingTop="5dp" />
<Button
android:id="@+id/btn_like"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/seperator"
android:background="@android:color/transparent"
android:drawableLeft="@drawable/date_btn_selector"
android:drawablePadding="5dp"
android:minHeight="0dp"
android:minWidth="0dp"
android:paddingBottom="5dp"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:paddingTop="5dp"
android:text=""
android:textSize="14sp" />
<!-- android:textColor="#01B275"-->
</RelativeLayout>
<RelativeLayout
android:id="@+id/Relative2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:layout_below="@+id/Relative1"
android:layout_alignParentStart="true">
<TextView
android:id="@+id/title_text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:maxLines="5"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:paddingTop="7dp"
android:text="Title Text"
android:textColor="@color/intouch_green"
android:textSize="14sp" />
<TextView
android:id="@+id/my_text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title_text2"
android:layout_marginBottom="3dp"
android:ellipsize="end"
android:maxLines="1"
android:paddingBottom="7dp"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:text=""
android:textSize="12sp" />
<!-- android:textColor="#9B9BA5" -->
<TextView
android:id="@+id/seperator2"
android:layout_width="fill_parent"
android:layout_height="1px"
android:layout_below="@+id/my_text2" />
<!-- android:background="#939393"-->
<Button
android:id="@+id/btn_save2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/seperator2"
android:background="@android:color/transparent"
android:drawableRight="@drawable/donecon"
android:minHeight="0dp"
android:minWidth="0dp"
android:paddingBottom="5dp"
android:paddingRight="7dp"
android:paddingTop="5dp" />
<Button
android:id="@+id/btn_like2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/seperator2"
android:background="@android:color/transparent"
android:drawableLeft="@drawable/accessoryp"
android:drawablePadding="5dp"
android:minHeight="0dp"
android:minWidth="0dp"
android:paddingBottom="5dp"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:paddingTop="5dp"
android:text=""
android:textSize="14sp" />
<!-- android:textColor="#01B275" -->
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>