Auto adjust LinearLayout and clone LinearLayout entirely - java

Good day!
I'll start with the 2 issues:
1.- I want a LinearLayour to autoadjust his content whenever necessary (Because I disabled an element on the layout).
2.- Clone a LinearLayout entirely depending on the size of an Array.
I have this code (yes, it is pretty big):
<TextView
android:id="#+id/textTitleScore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginStart="15dp"
android:text="Votaciones"
android:fontFamily="#font/segoeprint"
android:textColor="#color/ourBlack3"
android:contentDescription="#string/titleFinalEvent"
android:textSize="28sp"/>
<RelativeLayout
android:id="#+id/constraint_team"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="activateContent"
android:background="#drawable/finaleventteambackground"
android:backgroundTint="#color/ourOrange">
<ImageView
android:id="#+id/imageView"
android:layout_width="80dp"
android:layout_height="50dp"
android:layout_alignParentStart="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="10dp"
android:layout_centerVertical="true"
android:scaleType="fitXY"
android:src="#mipmap/littlelogomc" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="Equipo 1"
android:fontFamily="#font/seguisbi"
android:textColor="#color/ourWhite"
android:layout_marginRight="30dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginBottom="10dp"/>
</RelativeLayout>
<LinearLayout
android:id="#+id/team1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/finaleventteambackground">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:fontFamily="#font/segoeprint"
android:textColor="#color/ourBlack3"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Presentación"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<SeekBar
android:id="#+id/seekBarPresentation"
android:layout_width="240dp"
android:layout_height="30dp"
android:layout_marginLeft="10dp"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:progressDrawable="#drawable/custom_seekbar"
android:thumb="#drawable/thumb"/>
<RelativeLayout
android:layout_width="70dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:background="#drawable/edittextbackground"
android:layout_marginRight="20dp"
android:layout_alignParentEnd="true">
<EditText
android:id="#+id/editTextPresentation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_marginRight="5dp"
android:textAlignment="gravity"
android:layout_centerVertical="true"
android:textSize="20sp"
android:inputType="number"
android:background="#android:color/transparent"
android:hint="0"/>
</RelativeLayout>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:fontFamily="#font/segoeprint"
android:textColor="#color/ourBlack3"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
android:text="Servicio"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<SeekBar
android:id="#+id/seekBarService"
android:layout_width="240dp"
android:layout_height="30dp"
android:layout_marginLeft="10dp"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:progressDrawable="#drawable/custom_seekbar"
android:thumb="#drawable/thumb"/>
<RelativeLayout
android:layout_width="70dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:background="#drawable/edittextbackground"
android:layout_marginRight="20dp"
android:layout_alignParentEnd="true">
<EditText
android:id="#+id/editTextService"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_marginRight="5dp"
android:textAlignment="gravity"
android:layout_centerVertical="true"
android:textSize="20sp"
android:inputType="number"
android:background="#android:color/transparent"
android:hint="0"/>
</RelativeLayout>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:fontFamily="#font/segoeprint"
android:textColor="#color/ourBlack3"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
android:text="Sabor"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<SeekBar
android:id="#+id/seekBarFlavour"
android:layout_width="240dp"
android:layout_height="30dp"
android:layout_marginLeft="10dp"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:progressDrawable="#drawable/custom_seekbar"
android:thumb="#drawable/thumb"/>
<RelativeLayout
android:layout_width="70dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:background="#drawable/edittextbackground"
android:layout_marginRight="20dp"
android:layout_alignParentEnd="true">
<EditText
android:id="#+id/editTextFlavour"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_marginRight="5dp"
android:textAlignment="gravity"
android:layout_centerVertical="true"
android:textSize="20sp"
android:inputType="number"
android:background="#android:color/transparent"
android:hint="0"/>
</RelativeLayout>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:fontFamily="#font/segoeprint"
android:textColor="#color/ourBlack3"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
android:text="Imagen"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<SeekBar
android:id="#+id/seekBarImage"
android:layout_width="240dp"
android:layout_height="30dp"
android:layout_marginLeft="10dp"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:progressDrawable="#drawable/custom_seekbar"
android:thumb="#drawable/thumb"/>
<RelativeLayout
android:layout_width="70dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:background="#drawable/edittextbackground"
android:layout_marginRight="20dp"
android:layout_alignParentEnd="true">
<EditText
android:id="#+id/editTextImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_marginRight="5dp"
android:textAlignment="gravity"
android:layout_centerVertical="true"
android:textSize="20sp"
android:inputType="number"
android:background="#android:color/transparent"
android:hint="0"/>
</RelativeLayout>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:fontFamily="#font/segoeprint"
android:textColor="#color/ourBlack3"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
android:text="Tríptico"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<SeekBar
android:id="#+id/seekBarTriptych"
android:layout_width="240dp"
android:layout_height="30dp"
android:layout_marginLeft="10dp"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:progressDrawable="#drawable/custom_seekbar"
android:thumb="#drawable/thumb"/>
<RelativeLayout
android:layout_width="70dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:background="#drawable/edittextbackground"
android:layout_marginRight="20dp"
android:layout_alignParentEnd="true">
<EditText
android:id="#+id/editTextTriptych"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_marginRight="5dp"
android:textAlignment="gravity"
android:layout_centerVertical="true"
android:textSize="20sp"
android:inputType="number"
android:background="#android:color/transparent"
android:hint="0"/>
</RelativeLayout>
</RelativeLayout>
<androidx.appcompat.widget.AppCompatButton
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="20dp"
android:enabled="false"
android:background="#drawable/roundedbutton"
android:backgroundTint="#color/ourOrange"
android:text="Votar"
android:fontFamily="#font/segoeprint"
android:textFontWeight="700"
android:textColor="#color/ourWhite"
android:layout_gravity="center"
android:textSize="18sp"/>
</LinearLayout>
</LinearLayout>
The first RelativeLayout (+id/constraint_team), has an OnClick() event which disables or enables the next children LinearLayout (#+id/team1). But the parent LinearLayout(#+id/linear_score) doesn't adjust when I disable the children LinearLayout.
I was trying to achieve this with this code:
if (linearLayout.isEnabled())
{
for (int i = 0; i < linearLayout.getChildCount(); i++)
{
View v = linearLayout.getChildAt(i);
v.setVisibility(View.INVISIBLE);
v.setEnabled(false);
}
linearLayout.setVisibility(View.INVISIBLE);
linearLayout.setEnabled(false);
//linearLayoutScore.getLayoutParams().height = LinearLayout.LayoutParams.WRAP_CONTENT;
//ViewGroup.LayoutParams params = linearLayoutScore.getLayoutParams();
linearLayoutScore.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
linearLayoutScore.requestLayout();
}
(The comments are other unsuccessful attempts I have tried)
with this code, instead of only modifying the size of the parent LinearLayout, it modifies the entire screen to be only this parent LinearLayout. (I've read that set.LayoutParams only modify the layout height and width, but it doesn't seems to work like that).
For the second one I haven't found anything useful (maybe i'm just using really bad keyword on google), Basically if I receive a number, for example 3, I want to copy my child LinearLayout and my RelativeLayout (#+id/constraint_team and #+id/team1) that many times, How can I achieve this?
Thanks in advance

Related

Android Textview is moved to right

This is what I actually have as a result:
As you can see value to right of Current HP is moved to right instead to stay close to "Current HP" textview like the rest of values. Why is that so? This is my code:
<?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"
android:layout_width="match_parent"
android:background="#color/semiTrans"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/llHeader"
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/text"
android:layout_marginRight="5dp"
app:srcCompat="#android:drawable/ic_dialog_info" />
<TextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="center_vertical|center_horizontal"
android:text="CONTINUE INFO"
android:textColor="#000"
android:textSize="25sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl2"
android:layout_marginHorizontal="10dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/llHeader"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true">
<TextView
android:id="#+id/currentHp"
android:textStyle="bold"
android:layout_width="168dp"
android:layout_height="wrap_content"
android:text="Current HP: "
android:textSize="18sp"/>
<TextView
android:id="#+id/nextHp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/currentHp"
android:text="Next +10HP: "
android:textSize="18sp"/>
<TextView
android:id="#+id/fullHp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/nextHp"
android:text="HP fully recovered: "
android:textSize="18sp"/>
<TextView
android:id="#+id/currentHpValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/currentHp"
android:layout_toRightOf="#+id/currentHp"
android:text="a"
android:textSize="18sp"/>
<TextView
android:id="#+id/nextHpValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/currentHp"
android:layout_toEndOf="#+id/nextHp"
android:layout_toRightOf="#+id/nextHp"
android:text="a"
android:textSize="18sp"/>
<TextView
android:id="#+id/fullHpValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/fullHp"
android:layout_alignBottom="#+id/fullHp"
android:layout_toEndOf="#+id/fullHp"
android:layout_toRightOf="#+id/fullHp"
android:text="a"
android:textSize="18sp"/>
<TextView
android:id="#+id/tvAdditionalInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_below="#id/fullHp"
android:textSize="18sp"
android:layout_centerHorizontal="true"
android:text="Additional info"/>
</RelativeLayout>
<Button
android:id="#+id/dialogButtonOK"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rl2"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginHorizontal="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/button"
android:text=" Ok " />
</RelativeLayout>
I was trying to solve this by setting padding and margin to 0 but it did not work. I do not know what else Ishould added.
I found a solution. I need to set currentHp textview width to wrap content.
Your current Hp has a width 168 dp.
For this reason it is taking that place and after that place your a text is showing.
So you have make the width of current Hp to wrap-content . Then the text a will stay like others.
You can check this code to solve the issue
<?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"
android:layout_width="match_parent"
android:background="#color/semiTrans"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/llHeader"
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/text"
android:layout_marginRight="5dp"
app:srcCompat="#android:drawable/ic_dialog_info" />
<TextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="center_vertical|center_horizontal"
android:text="CONTINUE INFO"
android:textColor="#000"
android:textSize="25sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl2"
android:layout_marginHorizontal="10dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/llHeader"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true">
<TextView
android:id="#+id/currentHp"
android:textStyle="bold"
android:layout_width="168dp"
android:layout_height="wrap_content"
android:text="Current HP: "
android:textSize="18sp"/>
<TextView
android:id="#+id/nextHp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/currentHp"
android:layout_marginEnd="62dp"
android:layout_toStartOf="#+id/currentHpValue"
android:text="Next +10HP: "
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/fullHp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/nextHp"
android:layout_marginEnd="10dp"
android:layout_toStartOf="#+id/currentHpValue"
android:text="HP fully recovered: "
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/currentHpValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/currentHp"
android:layout_toRightOf="#+id/currentHp"
android:text="a"
android:textSize="18sp"/>
<TextView
android:id="#+id/nextHpValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/currentHp"
android:layout_toEndOf="#+id/nextHp"
android:layout_toRightOf="#+id/nextHp"
android:text="a"
android:textSize="18sp"/>
<TextView
android:id="#+id/fullHpValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/fullHp"
android:layout_alignBottom="#+id/fullHp"
android:layout_toEndOf="#+id/fullHp"
android:layout_toRightOf="#+id/fullHp"
android:text="a"
android:textSize="18sp"/>
<TextView
android:id="#+id/tvAdditionalInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_below="#id/fullHp"
android:textSize="18sp"
android:layout_centerHorizontal="true"
android:text="Additional info"/>
</RelativeLayout>
<Button
android:id="#+id/dialogButtonOK"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rl2"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginHorizontal="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/button"
android:text=" Ok " />
</RelativeLayout>

why doesn't my banner appear in Linearlayout?

I am using relative layout in linear layout.My banner appears on the design screen, but no ads appear when I run my application.I looked at many examples but I could not find.My application was horizontal before now I'm designing vertically.Previously I was using Relativelayout then my banner was working.Here my code;
<?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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:weightSum="12"
android:background="#fffdd0">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="2">
<RelativeLayout
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_centerHorizontal="true">
<Button
android:id="#+id/btn_double"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_alignParentStart="true"
android:background="#drawable/xx"
android:layout_marginTop="15dp"/>
<Button
android:id="#+id/btn_yariyariya"
android:layout_width="47dp"
android:layout_height="47dp"
android:background="#drawable/fiftyfifty"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"/>
<Button
android:id="#+id/btn_skip"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_alignParentEnd="true"
android:background="#drawable/skip"
android:layout_marginTop="15dp"/>
<TextView
android:id="#+id/tv_countdown2x"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="13sp"
android:layout_alignParentStart="true"
android:textColor="#color/colorPrimary"
android:layout_below="#+id/btn_double" />
<TextView
android:id="#+id/tv_countdown50"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:layout_centerHorizontal="true"
android:textColor="#color/colorPrimary"
android:layout_below="#+id/btn_yariyariya"/>
<TextView
android:id="#+id/tv_countdownNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="13sp"
android:layout_alignParentEnd="true"
android:textColor="#color/colorPrimary"
android:layout_below="#+id/btn_skip"/>
<TextView
android:id="#+id/tv_countdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="00:30"
android:textSize="30sp"
android:layout_centerHorizontal="true"
android:textColor="#color/colorPrimary"
android:layout_marginTop="85dp" />
<FrameLayout
android:id="#+id/container_pop_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_marginTop="16dp" />
</RelativeLayout>
<TextView
android:id="#+id/tv_countdown1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:layout_marginStart="40dp"
android:layout_marginTop="60dp"
android:textColor="#color/colorPrimary"/>
<Button
android:id="#+id/btn_kalp1"
android:layout_width="50dp"
android:layout_height="40dp"
android:background="#drawable/kalp"
android:layout_alignParentStart="true"
android:layout_marginStart="30dp"
android:layout_marginTop="15dp"/>
<Button
android:id="#+id/btn_satinal"
android:layout_width="50dp"
android:layout_height="40dp"
android:layout_marginStart="200dp"
android:onClick="satinalMain"
android:background="#drawable/satinal"
android:layout_alignParentEnd="true"
android:layout_marginEnd="30dp"
android:layout_marginTop="15dp"/>
<TextView
android:id="#+id/tv_kalp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="5"
android:textColor="#color/colorPrimary"
android:layout_alignParentStart="true"
android:layout_marginTop="25dp"
android:layout_marginStart="84dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10sp"
android:text="X"
android:textColor="#color/colorPrimary"
android:layout_alignParentStart="true"
android:layout_marginTop="35dp"
android:layout_marginStart="77dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="3">
<TextView
android:id="#+id/tv_soru"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000"
android:fontFamily="#font/incee"
android:gravity="center"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:textAlignment="gravity"
android:textSize="18sp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="5"
android:orientation="vertical">
<Button
android:id="#+id/btn_a"
android:layout_width="260dp"
android:layout_height="60dp"
android:textColor="#000"
android:background="#drawable/gradient"
android:gravity="center"
android:textAlignment="gravity"
android:fontFamily="#font/incee"
android:textSize="12sp"
android:layout_centerHorizontal="true"/>
<Button
android:id="#+id/btn_b"
android:layout_width="260dp"
android:layout_height="60dp"
android:layout_below="#+id/btn_a"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:background="#drawable/gradient"
android:fontFamily="#font/incee"
android:gravity="center"
android:textAlignment="gravity"
android:textColor="#000"
android:textSize="12sp" />
<Button
android:id="#+id/btn_c"
android:layout_width="260dp"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:background="#drawable/gradient"
android:fontFamily="#font/incee"
android:gravity="center"
android:textAlignment="gravity"
android:textColor="#000"
android:textSize="12sp"
android:layout_below="#+id/btn_b"
android:layout_marginTop="5dp"/>
<Button
android:id="#+id/btn_d"
android:layout_width="260dp"
android:layout_height="60dp"
android:textColor="#000"
android:background="#drawable/gradient"
android:gravity="center"
android:textAlignment="gravity"
android:fontFamily="#font/incee"
android:textSize="12sp"
android:layout_below="#+id/btn_c"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"/>
<Button
android:id="#+id/btn_infoA"
android:layout_width="40dp"
android:layout_height="45dp"
android:background="#drawable/info"
android:layout_centerVertical="true"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>
<Button
android:id="#+id/btn_gec"
android:layout_width="65dp"
android:layout_height="60dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="1dp"
android:background="#drawable/next"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1">
<TextView
android:id="#+id/tv_skor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:text="0"
android:textColor="#000"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="25dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:text="SKOR :"
android:textColor="#000"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="50dp"
android:layout_marginBottom="5dp"/>
<Button
android:id="#+id/btn_reklam"
android:layout_width="50dp"
android:layout_height="45dp"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="5dp"
android:background="#drawable/plus"
android:onClick="startVideoAd"/>
<TextView
android:id="#+id/tv_kalp_kazan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="İzle Kazan"
android:layout_alignParentStart="true"
android:textSize="15sp"
android:textStyle="bold"
android:layout_alignParentBottom="true"
android:fontFamily="#font/incee"
android:textColor="#000"
android:layout_marginStart="55dp"
android:layout_marginBottom="5dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1">
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3101578796185185/4912585915">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
I think it's because the bannerview is lower than your screen! (Maybe you're using this layout for a fragment and your activity has a toolbar, am I right?)
Just put LinearLayout inside a ScrollView and see if it works.
Your layout design is not very well done, the buttons at the center (first RelativeLayout) are not constrained to the adjacent buttons, so they may overlap.
You should use a ConstraintLayout instead of RelativeLayout, the later is obsolete now.
You have several items with wrap_content height inside a layout that you want to stretch vertically, which is contradictory. This may cause views inside the inner RelativeLayouts to be hidden if they are smaller than the height.
weightSum is a property that is rarely useful because weights are calculated automatically, you should simply know that two views with 1 and 1 with use 50% each, and if you add another with weight 2 it will have proportionally that weight. So it will end up 25%, 25% and 50%.
There is no need to place the AdView inside a RelativeLayout if it is the only view there.
If you want the banner to be always visible, then simply place a default height (either wrap_content or a given height in dps). The other views will use the remaining space to calculate the weight space.
I recommend you to first study how different Layouts work before attempting to build your screen layout.
On the other hand, the AdView requires some additional configuration on your end to become shown, because if you did not setup some campaign to be shown, the view won't display anything.

Bottom views of the xml layout are not showing up

This is my register layout. The views which are below password i.e spinners,buttons are not showing up in my phone but its showing up in the emulator...My emualtor is based on nexus 7 whereas my phone is samsung grand..I m wondering what is happening there..Is something wrong in my code.
please help
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/gradient"
>
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#drawable/topimg" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#000750"
android:padding="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="50dp"
android:layout_marginLeft="20dp"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#fff"
android:id="#+id/register_error"
android:textSize="15dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="left"
android:textSize="15dp"
android:textColor="#000"
android:layout_marginTop="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:id="#+id/fname"
android:background="#FFF"
android:hint="#string/name"
></EditText>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="left"
android:textSize="15dp"
android:textColor="#000"
android:layout_marginTop="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:id="#+id/lname"
android:background="#FFF"
android:hint="#string/lname"
></EditText>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="left"
android:textSize="15dp"
android:textColor="#000"
android:layout_marginTop="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:id="#+id/uname"
android:background="#FFF"
android:hint="#string/username"
></EditText>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="left"
android:textSize="15dp"
android:textColor="#000"
android:layout_marginTop="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:id="#+id/email"
android:background="#FFF"
android:hint="#string/semail"
></EditText>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="left"
android:textSize="15dp"
android:textColor="#000"
android:layout_marginTop="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:id="#+id/pword"
android:background="#FFF"
android:hint="#string/password"
android:password="true"
></EditText>
<Spinner
android:id="#+id/spinner1"
android:spinnerMode="dialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Select"
android:entries="#array/level_arrays"
android:prompt="#string/level_prompt"
android:layout_marginTop="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:background="#FFF"
/>
<Spinner
android:id="#+id/spinner2"
android:spinnerMode="dialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/class_arrays"
android:prompt="#string/class_prompt"
android:layout_marginTop="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:background="#FFF"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="20dp"
android:textColor="#FFF"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="Enroll"
android:id="#+id/register"
android:background="#589700"
></Button>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="20dp"
android:textColor="#FFF"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="Back To Login"
android:id="#+id/bktologin"
android:background="#589700"
></Button>
</LinearLayout>
</LinearLayout>
Problem is the height of your inner linear layout is more than the screen size. To solve this problem, you can add a extra scroll view and put this linear layout to the scroll view.

Push keyboard to layout

I have an edittext, and when I focus on that, the footer layout was pushed together. How to hide footer when focus on edittext.
Before focus
After focus
this is my source code
<ListView
android:id="#+id/list_chat_rom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/rl_footer_send"
android:divider="#android:color/transparent"
android:dividerHeight="5dp"></ListView>
<RelativeLayout
android:id="#+id/rl_footer_send"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/menu_bar_bg">
<RelativeLayout
android:id="#+id/rl_insert_chat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="10dp">
<ImageView
android:id="#+id/btn_send_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/layout_imv_send_message" />
<EditText
android:id="#+id/edit_insert_chat"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="#id/btn_send_msg"
android:background="#drawable/layout_edit_text_chat"
android:hint="type to filter"
android:inputType="text"
android:maxLines="1"
android:textColor="#color/black" />
</RelativeLayout>
<View
android:id="#+id/view_line"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="#id/rl_insert_chat"
android:background="#color/black"></View>
<RelativeLayout
android:id="#+id/rl_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/view_line"
android:paddingBottom="5dp"
android:paddingLeft="20dp"
android:paddingRight="10dp"
android:paddingTop="5dp">
<ImageView
android:id="#+id/imv_avatar_chat"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:scaleType="centerCrop" />
<RelativeLayout
android:id="#+id/rl_content_home"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/imv_avatar_chat">
<TextView
android:id="#+id/tv_name_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="user name"
android:textColor="#color/white" />
<TextView
android:id="#+id/tv_level"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tv_name_user"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="lv : 10"
android:textColor="#color/white" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_marginRight="10dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:src="#drawable/target_icon" />
<TextView
android:id="#+id/tv_point_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10/125" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="10dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:src="#drawable/gem_icon" />
<TextView
android:id="#+id/tv_xu_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="100" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<TextView
android:id="#+id/tv_login_facebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="#id/imv_avatar_home"
android:text="ĐĂNG NHẬP BẰNG FACEBOOK"
android:visibility="gone" />
</RelativeLayout>
</RelativeLayout>
Why don't you try to hide it?
You can try to detect the keyboard state with this :
final View activityRootView = findViewById(R.id.activityRoot);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
... do something here
}
}
});
Note : Taken from here
And then you just hide the view that you want to hide.
Try with
android:windowSoftInputMode="adjustPan"
in the Activity declaration in the manifest

ImageView not displayed into layout

i have a problem with a layout. I'm using SlidingUpPanel and i would like to jave an ImageView below a TextView. The code is this.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="#+id/panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:panelHeight="70dp"
sothree:shadowHeight="4dp"
sothree:paralaxOffset="100dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.simonedev.player.utils.PagerSlidingTabStrip
android:id="#+id/pagerTabStrip"
android:layout_width="match_parent"
android:layout_height="50dip"
android:background="#drawable/my_drawable"/>
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/pagerTabStrip"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eeeeee"
android:orientation="vertical">
<ImageView
android:id="#+id/myImage1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="20dp"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:src="#drawable/ic_action_im"/>
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginRight="15dp"
android:layout_marginEnd="15dp"
android:layout_alignParentLeft="true"
android:fontFamily="sans-serif-condensed"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:textSize="18sp"/>
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_below="#+id/text1"
android:fontFamily="sans-serif-light"
android:textSize="15sp"/>
<RelativeLayout
android:id="#+id/relative"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginLeft="25dp"
android:layout_marginStart="25dp"
android:layout_marginBottom="75dp"
android:textSize="17sp"
android:text="0:00"/>
<SeekBar
android:id="#+id/seekBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_marginRight="55dp"
android:layout_marginEnd="55dp"
android:layout_marginBottom="70dp"
android:layout_toRightOf="#+id/text3"
android:layout_toEndOf="#+id/text3"
android:layout_alignParentBottom="true"
android:max="100"/>
<TextView
android:id="#+id/text4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="22dp"
android:layout_marginEnd="22dp"
android:layout_marginBottom="75dp"
android:textSize="17sp"/>
<ImageView
android:id="#+id/myImage2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="20dp"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:src="#drawable/ic_action_im2"
android:layout_below="#+id/text4"/>
</RelativeLayout>
</RelativeLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
</RelativeLayout>
Now, the problem is that myImage2 is not displayed when i run my app and i don't understand why. Where is the error? How can i solve?
Your image is outside the display
<ImageView android:id="#+id/myImage2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignRight="#+id/seekBar"
android:layout_alignTop="#+id/text3"
android:layout_marginEnd="10dp"
android:layout_marginRight="121dp"
android:layout_marginTop="20dp"
android:src="#drawable/ic_action_im2" />
Just check with above code

Categories