Buenas estoy intentando crear un Cardview pero este se me sale del LinearLayout, les paso el código para ver si pueden ayudarme soy principiante y de seguro estoy haciendo algo mal.
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);
Este es el código de mi actividad en 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>
Esta es la imagen de como me sale mi Cardview:
como puede ver en la parte de abajo es cuando intento crear el CardVieW haciendo click en un boton pero este se me sale del LinearLayout espero puedan ayudarme.