Good I am trying to create a Cardview but this one leaves me of the LinearLayout, I pass them the code to see if they can help me I am a beginner and surely I am doing something bad.
LinearLayout.LayoutParams lParams = new LinearLayout.LayoutParams(
R.id.wrap_content, R.id.wrap_content);
layoutparams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT
);
layoutparams.height = 40;
layoutparams.width = 40;
CardView catCard = new CardView(getApplicationContext());
catCard.setLayoutParams(new CardView.LayoutParams(
CardView.LayoutParams.MATCH_PARENT, 10));
catCard.setMinimumHeight(10);
catCard.setCardBackgroundColor(Color.parseColor("#FFC6D6C3"));
content.addView(catCard);
This is the code of my activity in xml
:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.omar.versionmejorada.Main2Activity"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/id_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<android.support.v7.widget.CardView
android:id="@+id/card3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_alignParentTop="true"
android:src="@drawable/maxresdefault"
android:scaleType="centerCrop"/>
<TextView
android:id="@+id/txt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Buenos Aires2"
android:textColor="#121111"
android:textStyle="bold"
android:textSize="22dp" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/card2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_alignParentTop="true"
android:src="@drawable/maxresdefault"
android:scaleType="centerCrop"/>
<TextView
android:id="@+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Buenos Aires"
android:textColor="#121111"
android:textStyle="bold"
android:textSize="22dp" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>
This is the image of how my Cardview works:
As you can see at the bottom is when I try to create the CardVieW by clicking on a button but it comes out of the LinearLayout I hope you can help me.