我在RelativeLayout中实现CardView有问题。我将CardView设置在RelativeLayout的后面位置。但这似乎不是我想要的。
这是xml:
for x in range(0, len(my_hexplode_chains) - 1):
match_found = False
for y in range(x + 1, len(my_hexplode_chains)):
for tile_id_x, tile_x in my_hexplode_chains[x].items(): #compare each chain in list
for tile_id_y, tile_y in my_hexplode_chains[y].items(): #to every other chain
for neighbour in tile_x["neighbours"]: #if tiles in different lists
if neighbour == tile_id_y: #are neighbours
match_found = True
my_hexplode_chains[x].update(my_hexplode_chains[y]) #append one chain to the other
del my_hexplode_chains[y] #delete appended chain
if match_found: #continue loop at next chain
break #very ugly way to do this
if match_found:
break
if match_found:
break
if match_found:
break
我也实现了<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="4dp">
<android.support.v7.widget.CardView
android:id="@+id/root_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground"
android:descendantFocusability="blocksDescendants"
card_view:cardCornerRadius="10dp"
android:layout_alignBottom="@+id/layout_isi"
android:layout_alignLeft="@+id/layout_isi"
android:layout_alignTop="@+id/layout_isi"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/layout_isi"/>
<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/layout_isi"
android:layout_marginLeft="8dp"
android:layout_below="@+id/layout_business_name_child">
<android.support.percent.PercentRelativeLayout
android:id="@+id/left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_widthPercent="75%">
<LinearLayout
android:id="@+id/layout_thumbnail_business"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_widthPercent="50%">
<com.kamardagang.utils.ResizeImageView
android:id="@+id/thumbnail_business"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:src="@drawable/placeholder" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/layout_thumbnail_business"
android:orientation="vertical"
app:layout_widthPercent="50%">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.joanzapata.iconify.widget.IconTextView
android:id="@+id/icon_status_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:text="@string/fa_minus_circle" />
<RatingBar
android:id="@+id/business_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center" />
<com.kamardagang.utils.TimesNewRomansTextView
android:id="@+id/status_rating"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="left|center"
android:padding="10dp"
android:text="status_rating" />
</LinearLayout>
<com.kamardagang.utils.TimesNewRomansTextView
android:id="@+id/business_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="business_title"
android:textAppearance="?android:attr/textAppearanceMedium" />
<com.kamardagang.utils.TimesNewRomansTextView
android:id="@+id/business_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:paddingBottom="0dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:text="business_name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
<com.kamardagang.utils.TimesNewRomansTextView
android:id="@+id/business_status"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="0dp"
android:text="business_status"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</android.support.percent.PercentRelativeLayout>
<LinearLayout
android:id="@+id/right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/left"
android:orientation="vertical"
app:layout_widthPercent="25%">
<com.joanzapata.iconify.widget.IconButton
android:id="@+id/count_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#337ab7"
android:text="@string/star"
android:textColor="@color/white" />
<com.joanzapata.iconify.widget.IconButton
android:id="@+id/view_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lihat_rating" />
</LinearLayout>
</android.support.percent.PercentRelativeLayout>
<android.support.v7.widget.CardView
android:id="@+id/layout_business_name_child"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
app:cardBackgroundColor="#337ab7"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
<com.kamardagang.utils.TimesNewRomansTextView
android:id="@+id/business_name_child"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="business_name"
android:textColor="@color/white"/>
</android.support.v7.widget.CardView>
</RelativeLayout>
,但它不起作用,所以如何修复它? sory for my English
答案 0 :(得分:0)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="4dp">
<android.support.v7.widget.CardView
android:id="@+id/root_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="false"
android:layout_below="@+id/layout_business_name_child"
android:background="?android:attr/selectableItemBackground"
android:descendantFocusability="blocksDescendants"
card_view:cardCornerRadius="10dp">
<android.support.percent.PercentRelativeLayout
android:id="@+id/layout_isi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/layout_business_name_child"
android:layout_marginLeft="8dp">
<android.support.percent.PercentRelativeLayout
android:id="@+id/left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_widthPercent="75%">
<LinearLayout
android:id="@+id/layout_thumbnail_business"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_widthPercent="50%">
<ImageView
android:id="@+id/thumbnail_business"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:src="@mipmap/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/layout_thumbnail_business"
android:orientation="vertical"
app:layout_widthPercent="50%">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/icon_status_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:text="Test" />
<RatingBar
android:id="@+id/business_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center" />
<TextView
android:id="@+id/status_rating"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="left|center"
android:padding="10dp"
android:text="status_rating" />
</LinearLayout>
<TextView
android:id="@+id/business_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="business_title"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/business_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:paddingBottom="0dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:text="business_name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
<TextView
android:id="@+id/business_status"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="0dp"
android:text="business_status"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</android.support.percent.PercentRelativeLayout>
<LinearLayout
android:id="@+id/right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/left"
android:orientation="vertical"
app:layout_widthPercent="25%">
<Button
android:id="@+id/count_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#337ab7"
android:text="Test"
android:textColor="@android:color/black" />
<Button
android:id="@+id/view_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test" />
</LinearLayout>
</android.support.percent.PercentRelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/layout_business_name_child"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:descendantFocusability="blocksDescendants"
app:cardBackgroundColor="#337ab7">
<TextView
android:id="@+id/business_name_child"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="business_name"
android:textColor="@android:color/black" />
</android.support.v7.widget.CardView>
</RelativeLayout>
我将PercentRelativeLayout
放在CardView
内并且有效。
希望这会有所帮助:)