-1

На самом деле я работаю над макетом, в котором я должен поставить CardView на ImageView, и он охватывает только половину части ImageView, а также добавляет один TextView (Check Attach Image) ,Как создать этот вид (макет)

Примечание:

  1. Я попытался с помощью FrameLayout, а также с относительной макете ... и я достиг этого, но я не думаю, что его правильный путь, потому что я зашит в основном paramters.

enter image description here

XML код:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/toolbar"> 
    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     > 
    <ImageView 
    android:layout_width="match_parent" 
    android:layout_height="170dp" 
    android:layout_gravity="center" 
    android:background="@drawable/background" 
    android:id="@+id/picture"> 
</ImageView> 

    <TextView 
     android:text="TEXT VIEW" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="149dp" 
     android:layout_marginStart="149dp" 
     android:layout_marginTop="24dp" 
     android:id="@+id/textView" /> 
    </FrameLayout> 
</LinearLayout> 

<android.support.v7.widget.CardView 
    android:layout_width="match_parent" 
    android:layout_height="120dp" 
    app:cardBackgroundColor="@color/textViewBackground" 
    card_view:cardUseCompatPadding="true" 
    android:layout_centerHorizontal="true" 
    card_view:cardElevation="15sp" 
    android:layout_marginTop="153dp" /> 
+0

Вы пытались сделать это? Если да, то разместить код XML – Vishwa

+0

пожалуйста, проверьте мой код –

+0

эй бр вы дали жестко закодированные поля в своем коде –

ответ

1

попробовать это:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout android:layout_width="match_parent" 
android:layout_height="match_parent" 
xmlns:android="http://schemas.android.com/apk/res/android" > 

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="200dp" 
    android:background="@android:color/white" 
    android:layout_alignParentTop="true"/> 

<TextView 
    android:layout_width="250dp" 
    android:layout_height="50dp" 
    android:layout_margin="20dp" 
    android:layout_centerHorizontal="true" 
    android:background="@color/colorAccent"/> 

<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:layout_width="match_parent" 
    android:layout_height="200dp" 
    android:layout_marginTop="100dp" 
    card_view:cardCornerRadius="8dp" 
    android:layout_marginLeft="30dp" 
    android:layout_marginRight="30dp" 
    card_view:cardBackgroundColor="@color/colorPrimary"> 


</android.support.v7.widget.CardView> 
</RelativeLayout> 

, если вы не хотите, чтобы жёстко параметры затем обратитесь по этой ссылке, чтобы получить ширину устройства высота во время выполнения

Get screen dimensions in pixels

, а затем вы можете использовать LayoutParams для динамического задания полей.

+0

на самом деле я не хочу жестко задавать параметры (android: layout_height = "200dp") –

+0

@DhruvTyagi см. мое редактирование –

+0

oky, поэтому у меня есть сомнения, - это необходимость создания нескольких размер экрана xml? –

0

Привет проверить это я редактировал код

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 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/tools" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/toolbar"> 
     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      > 
      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="170dp" 
       android:layout_gravity="center" 
       android:background="@color/colorPrimary" 
       android:id="@+id/picture"> 
      </ImageView> 

      <TextView 
       android:text="TEXT VIEW" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="149dp" 
       android:layout_marginStart="149dp" 
       android:background="@color/colorBlueColor" 
       android:layout_marginTop="24dp" 
       android:id="@+id/textView" /> 
     </FrameLayout> 

     <android.support.v7.widget.CardView 
      android:layout_width="match_parent" 
      android:layout_height="120dp" 
      app:cardBackgroundColor="@color/textViewBackground" 
      card_view:cardUseCompatPadding="true" 
      android:layout_centerHorizontal="true" 
      android:layout_marginLeft="100dp" 
      card_view:cardElevation="15sp" 
      android:layout_marginTop="100dp" /> 

    </RelativeLayout> 



</LinearLayout> 
0

Попробуйте, как он будет работать

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:arc="http://schemas.android.com/apk/res-auto" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:gravity="center" > 

    <ImageView 
     android:id="@+id/imageView1s" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:scaleType="fitXY" 
     android:src="@drawable/done" /> 

    <android.support.v7.widget.CardView 
     android:layout_width="130dp" 
     android:layout_height="130dp" 
     android:layout_marginTop="-65dp" 
     android:layout_below="@+id/imageView1s" 
     android:layout_centerHorizontal="true" 
     android:contentDescription="@string/app_name" 
     android:scaleType="center" 
     /> 

</RelativeLayout> 
Смежные вопросы