我正在制作一个应用程序,我有一个cardview
,在该卡片视图中我在该图片视图上有一个imageview
我定位了我的其他组件。
现在我的问题是,当我开始在图像视图中使用布局时,我的设计编辑器变为空白,当从图像视图中删除布局时,图像再次显示
我尝试搜索但是我没有得到与此特定问题有关的任何内容如果我出错了请纠正我
下面是我的XML
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
app:cardCornerRadius="8dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/feed_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/club1"
android:scaleType="fitCenter">
<RelativeLayout>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/profile_image"
android:layout_width="96dp"
android:layout_height="96dp"
android:src="@drawable/ellipse"
android:layout_gravity="top|left"/>
<TextView
android:id="@+id/first_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="John Doe"
android:textSize="15sp"
android:textColor="@color/White"
android:layout_toRightOf="@+id/profile_image"/>
<TextView
android:id="@+id/second_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="checked in to"
android:textSize="9sp"
android:layout_toRightOf="@+id/first_text"
android:textColor="@color/White"/>
<TextView
android:id="@+id/third_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="W south"
android:textSize="15sp"
android:layout_toRightOf="@+id/second_text"
android:textColor="@color/White"/>
<TextView
android:id="@+id/fourth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/first_text"
android:text="beach mumbai"
android:textSize="15sp"
android:textColor="@color/White"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="30 mins ago."
android:textColor="@color/White"
android:textSize="9sp"
android:layout_toRightOf="@+id/fourth_text"
android:layout_below="@+id/second_text"/>
</RelativeLayout>
</ImageView>
</RelativeLayout>
</android.support.v7.widget.CardView>
答案 0 :(得分:0)
错误ImageView
关闭代码以及RelativeLayout
height
&amp; width
遗失了。请检查代码。
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
app:cardCornerRadius="8dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/feed_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/club1"
android:scaleType="fitCenter"></ImageView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/profile_image"
android:layout_width="96dp"
android:layout_height="96dp"
android:src="@drawable/ellipse"
android:layout_gravity="top|left" />
<TextView
android:id="@+id/first_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="John Doe"
android:textSize="15sp"
android:textColor="@color/White"
android:layout_toRightOf="@+id/profile_image" />
<TextView
android:id="@+id/second_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="checked in to"
android:textSize="9sp"
android:layout_toRightOf="@+id/first_text"
android:textColor="@color/White" />
<TextView
android:id="@+id/third_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="W south"
android:textSize="15sp"
android:layout_toRightOf="@+id/second_text"
android:textColor="@color/White" />
<TextView
android:id="@+id/fourth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/first_text"
android:text="beach mumbai"
android:textSize="15sp"
android:textColor="@color/White" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="30 mins ago."
android:textColor="@color/White"
android:textSize="9sp"
android:layout_toRightOf="@+id/fourth_text"
android:layout_below="@+id/second_text" />
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView
答案 1 :(得分:0)
你只是忘了给你高宽度 RelativeLayout
检查
您正在view
ImageView
<强> FYI 强>
一个
ImageView
不是ViewGroup
您无法在其中添加view
像这样更改您的布局
试试这个
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
app:cardCornerRadius="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:src="@drawable/abc" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:id="@+id/first_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="John Doe"
android:textColor="@color/colorPrimary"
android:textSize="15sp" />
<TextView
android:id="@+id/second_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="checked in to"
android:textColor="@color/colorPrimary"
android:textSize="9sp" />
<TextView
android:id="@+id/third_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="W south"
android:textColor="@color/colorPrimary"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="horizontal">
<TextView
android:id="@+id/fourth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="beach mumbai"
android:textColor="@color/colorPrimary"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/second_text"
android:layout_toRightOf="@+id/fourth_text"
android:text="30 mins ago."
android:textColor="@color/colorPrimary"
android:textSize="9sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:padding="10dp"
android:text="reply to abc............" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_message" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="40 likes" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
答案 2 :(得分:0)
问题在于,您将ImageView
视为ViewGroup
,而不是ViewGroup
。您只能在ImageView
内嵌套视图。您问题的最简单的解决方案是将您放在RelativeLayout
内的所有内容放入您的父<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
app:cardCornerRadius="8dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/feed_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/club1"
android:scaleType="fitCenter"/>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/profile_image"
android:layout_width="96dp"
android:layout_height="96dp"
android:src="@drawable/ellipse"
android:layout_gravity="top|left"/>
<TextView
android:id="@+id/first_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="John Doe"
android:textSize="15sp"
android:textColor="@color/White"
android:layout_toRightOf="@+id/profile_image"/>
<TextView
android:id="@+id/second_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="checked in to"
android:textSize="9sp"
android:layout_toRightOf="@+id/first_text"
android:textColor="@color/White"/>
<TextView
android:id="@+id/third_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="W south"
android:textSize="15sp"
android:layout_toRightOf="@+id/second_text"
android:textColor="@color/White"/>
<TextView
android:id="@+id/fourth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/first_text"
android:text="beach mumbai"
android:textSize="15sp"
android:textColor="@color/White"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="30 mins ago."
android:textColor="@color/White"
android:textSize="9sp"
android:layout_toRightOf="@+id/fourth_text"
android:layout_below="@+id/second_text"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
中,如下所示:
package.json