why doesn't my banner appear in Linearlayout? - java

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.

Related

Auto adjust LinearLayout and clone LinearLayout entirely

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

Relative layout how to align to other element instead of parent

I have a relative layout where i already aligned almost all elements like i want, but there are two elements at the right bottom(textView and the icon of forbiden photo), they are aligned related to the parent, the parent is not the photo.
I want to align those elements to the bottom of the image that i have:
here is a
expected results:
the rectangle is where i want the textView and the camera forbiden icon!
and here is the xml:
<LinearLayout 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="wrap_content">
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="142dp"
android:layout_gravity="center"
android:layout_margin="#dimen/card_margin"
android:elevation="3dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
card_view:cardCornerRadius="#dimen/card_specie_radius">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.example.afcosta.inesctec.pt.android.Helpers.NexusBoldTextView
android:id="#+id/Avaliation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/plantName"
android:layout_marginStart="92dp"
android:layout_marginTop="15dp"
android:text="Avalie a fotografia" />
<com.example.afcosta.inesctec.pt.android.Helpers.NexusBoldTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/plantPhoto"
android:textColor="#color/base"
android:layout_marginTop="4dp"
android:layout_toStartOf="#+id/cameraForbiden"
android:text="TextView" />
<ImageView
android:id="#+id/reportImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/color_cursor_white" />
<ImageView
android:id="#+id/plantPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginRight="16dp" />
<ImageView
android:id="#+id/userIcon"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_alignParentBottom="true"
android:layout_below="#id/plantPhoto"
android:src="#drawable/ic_user"
/>
<com.example.afcosta.inesctec.pt.android.Helpers.NexusBoldTextView
android:id="#+id/plantName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/plantPhoto"
android:textColor="#color/nephritis"
android:textSize="18sp" />
<ImageView
android:id="#+id/starIcon"
android:layout_width="23dp"
android:layout_height="23dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/plantName"
android:src="#drawable/ic_star"
android:layout_marginLeft="10dp"
/>
<ImageView
android:id="#+id/cameraForbiden"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_toRightOf="#+id/plantName"
android:layout_marginLeft="10dp"
android:src="#drawable/ic_no_photos"
android:layout_below="#id/plantPhoto"
/>
<com.example.afcosta.inesctec.pt.android.Helpers.NexusBoldTextView
android:id="#+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/plantPhoto"
android:textColor="#color/base"
android:layout_marginEnd="29dp"
android:layout_marginTop="8dp"
android:layout_toEndOf="#+id/userIcon"
android:layout_toLeftOf="#+id/userIcon"
android:paddingLeft="10px"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Use following code:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/plantPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginRight="16dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_margin="5dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/userIcon"
android:layout_width="15dp"
android:layout_height="15dp"
android:src="#drawable/ic_user"
/>
<com.example.afcosta.inesctec.pt.android.Helpers.NexusBoldTextView
android:id="#+id/plantName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/nephritis"
android:textSize="18sp" />
</LinearLayout>
</RelativeLayout>

Android ScrollView is not scrolling with a relative layout

I have the following xml layout but my scrollview is not scrolling when I run the app. What am I doing wrong? I am trying to use a Relative layout in the scrollview instead of a Linear Layout Here is the xml..
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/main_title"
android:textSize="30sp"
android:textStyle="bold"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="180dp"
android:layout_height="270dp"
android:id="#+id/movie_poster"
android:layout_weight="0.59"
android:layout_below="#+id/main_title"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Ratings:"
android:id="#+id/textView"
android:layout_alignTop="#+id/movie_poster"
android:layout_toRightOf="#+id/movie_poster"
android:layout_toEndOf="#+id/movie_poster"
android:layout_marginLeft="52dp"
android:layout_marginStart="52dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text=" 6.5"
android:textStyle="bold"
android:id="#+id/movie_rating"
android:layout_alignTop="#+id/textView"
android:layout_toRightOf="#+id/textView"
android:layout_toEndOf="#+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text=" 2015-01-01"
android:textStyle="bold"
android:id="#+id/movie_release_date"
android:layout_below="#+id/textView"
android:layout_alignLeft="#+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="180dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/movie_description"
android:layout_below="#+id/movie_poster"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</ScrollView>
That is because you set the height of the ScrollView to fill_parent.
Try using a LinearLayout with weight so it fills the space left over from the other views.
If you do not want to set it to a specific height, you can also add
android:fillViewport="true"
to your ScrollView

Android studio setting layout up like this

I've tried everything I can think of but can't get this layout working. It's a ListView that list matches in a row.
Row one is first match, and next row is second match, and so on. I don't don't mind the green strokes and borders.
Is it even possible?
See the deisgn here:
Here's an example implementation, it does however use negative margins, to overlap the thing I called badge.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#cdcdcd"
android:gravity="center_vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/score"
android:layout_below="#+id/badge"
android:background="#color/white"
android:orientation="vertical"
android:padding="16dp"
android:showDividers="middle">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView 1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView 2"/>
</LinearLayout>
<TextView
android:id="#+id/score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:padding="16dp"
android:text="0 vs 7"
android:layout_below="#+id/badge"
android:textSize="32sp"
android:textStyle="bold"/>
<LinearLayout
android:layout_below="#+id/badge"
android:id="#+id/right_table"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/score"
android:background="#color/white"
android:orientation="vertical"
android:padding="16dp"
android:showDividers="middle">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView 1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView 2"/>
</LinearLayout>
<TextView
android:id="#+id/badge"
android:layout_toRightOf="#id/score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#0f0"
android:layout_marginLeft="-12dp"
android:layout_marginBottom="-8dp"
android:text="Badge"
/>
</RelativeLayout>
To alternate the background simply set the background in getView in your adapter.
You'll need a custom adapter that fills the ListView (better use RecyclerView & an Adapter with ViehHolder), this row layout is taken from my own project, not exactly what you requested, but you'll get the idea. Just comment for further information.
<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="wrap_content"
>
<TextView
android:id="#+id/textV_player1"
android:text="player1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="40dp"
android:layout_marginEnd="40dp"
android:textSize="20sp"
android:paddingTop="15dp"
android:gravity="end"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/textV_vs"
android:layout_toStartOf="#+id/textV_vs" />
<TextView
android:id="#+id/textV_player2"
android:text="player2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingTop="15dp"
android:layout_alignBottom="#+id/textV_vs"
android:layout_toRightOf="#+id/textV_vs"
android:layout_toEndOf="#+id/textV_vs" />
<TextView
android:id="#+id/textV_vs"
android:text="vs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="40dp"
android:layout_marginEnd="40dp"
android:textSize="20sp"
android:layout_above="#+id/textV_points1"
android:layout_centerHorizontal="true" />
<TextView
android:id="#+id/textV_points1"
android:text="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingTop="3dp"
android:paddingBottom="15dp"
android:layout_below="#+id/textV_player1"
android:layout_alignRight="#+id/textV_player1"
android:layout_alignEnd="#+id/textV_player1" />
<TextView
android:id="#+id/textV_points2"
android:text="2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingTop="3dp"
android:paddingBottom="15dp"
android:layout_below="#+id/textV_player2"
android:layout_alignLeft="#+id/textV_player2"
android:layout_alignStart="#+id/textV_player2" />
<TextView
android:id="#+id/textV_vspoints"
android:text=":"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingBottom="15dp"
android:layout_below="#id/textV_vs"
android:layout_centerHorizontal="true" />
</RelativeLayout>

why is android:layout_above doesn't work in

I have this layout
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/comments_list" android:layout_gravity="center"
android:layout_below="#+id/phone_editText" android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" android:layout_above="#+id/bottom_container"
android:layout_alignRight="#+id/search_btn" android:layout_alignEnd="#+id/search_btn"/>
<AutoCompleteTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/phone_editText"
android:hint="enter phone"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="blocked"
android:id="#+id/isBlocked_cb"
android:layout_toStartOf="#+id/phone_editText"
android:layout_toLeftOf="#+id/phone_editText"
android:layout_above="#+id/comments_list"
android:checked="true" android:layout_alignParentTop="true" android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="search"
android:id="#+id/search_btn"
android:layout_toEndOf="#+id/phone_editText"
android:layout_toRightOf="#+id/phone_editText"
android:layout_above="#+id/comments_list"
android:layout_alignParentTop="true" android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" android:onClick="foo"/>
<RelativeLayout android:id="#+id/bottom_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true">
<AutoCompleteTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/comment_text"
android:hint="enter comment"
android:layout_alignParentBottom="true" android:layout_centerHorizontal="true"/>
<Button style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Add" android:id="#+id/add_btn"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/comment_text" android:layout_alignTop="#+id/comment_text"/>
</RelativeLayout>
<LinearLayout
android:focusable="true" android:focusableInTouchMode="true"
android:layout_width="0px" android:layout_height="0px"/>
</RelativeLayout>
I want bottom_container to be below my ListView
but in the simulator they seems one above the other:
Your question it's pretty incomplete, but I see some potential error in your xml about "above"
For example
android:layout_above="#+id/comments_list"
android:layout_alignParentTop="true" android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" android:onClick="foo"/>
This is an error, you can not declare align parent top and end togheter... and in any case, If I'm right, those ovverride layout_above.

Categories