Make space for ads height - android

Hello and Happy new year!
I'm having a strange problem with banner ads height in my activity.
Basically the ads dimensions are 320x50dp but in logcat i can see it has only 320x0dp.
This obviously means that there's not enough space to load ads height but i don't know how to fix...
My contant_main is here:
<RelativeLayout 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"
xmlns:ads="http://schemas.android.com/apk/res-auto".
android:layout_width="match_parent"
android:layout_height="match_parent"
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=".MainActivity"
tools:showIn="#layout/activity_main">
<LinearLayout
android:id="#+id/aboutLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_horizontal"
android:weightSum="1">
<ImageView
android:id="#+id/imageView1"
android:layout_width="400dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:contentDescription="Header picture"
android:importantForAccessibility="no"
android:maxHeight="57dp"
android:maxWidth="57dp"
android:src="#drawable/xm"
android:layout_marginBottom="15dp"/>
</LinearLayout>
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_below="#id/aboutLinearLayout">
<LinearLayout
android:id="#+id/aboutLinearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_horizontal"
android:weightSum="1">
// some Switches and textviews here that i can't show you
</LinearLayout>
</ScrollView>
// Using this form to show ads becouse i don't want that it overrides scrollview when it's shown
<LinearLayout
android:id="#+id/layoutadmob"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_below="#id/scrollView">
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</LinearLayout></RelativeLayout>
Any one knows how can i free up enough space in app layout to show my banner?
Thanks

Your LinearLayout at the bottom is under the scrollView, which is right, but the ScrollView height is 'wrap_content' which make it all the way down in the page.
Add an attribute
android:layout_alignParentBottom
and set it to true.

Related

place an image between other elements so that it scales to fit all screens while keeping aspect ration intact

I want to do that in my xml. Currently I'm doing this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
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.example.MainActivity">
<ImageView
android:id="#+id/main_drawable_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/text" />
<LinearLayout
android:id="#+id/main_drawable_logo"
android:layout_width="match_parent"
android:layout_below="#id/main_drawable_text"
android:layout_height="wrap_content">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.1"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:src="#drawable/logo" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_below="#id/main_drawable_logo"
android:layout_height="wrap_content">
<TextView
android:id="#+id/credits"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content"
android:text="#string/credits" />
</LinearLayout>
</RelativeLayout>
In my testing device I only get part of the #drawable/logo, the rest falls out of the screen as does the credit's text. I can of course adjust the weight until I have the desired outcome, but how can I make sure I will get the expected result on all devices?
What I want is main_drawable_text always matching the width of the screen (from margin to margin), credits always being on the bottom of the screen and drawable_logo been scaled to fit the free space between them, yet with the original aspect ratio.
If I well understand UI you want to design you don't need LinearLayout but only existing RelativeLayout and inside it you can place your element according to each others positions (with android:layout_above, android:layout_below and so on). To keep original ratio of your drawable use android:scaleType="fitCenter".
Here is a layout which display (my interpretation of) what you want:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<ImageView
android:id="#+id/main_drawable_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="#drawable/text"/>
<ImageView
android:id="#+id/logo"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_above="#id/credits"
android:layout_below="#id/main_drawable_text"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="#drawable/logo"/>
<TextView
android:id="#+id/credits"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/credits"/>
</RelativeLayout>

android Layout - scrollview don't show

I have a ScrollView which contains EditText, but the problem is it doesn't show properly in the emulator and on a physical device. Can anyone see any problems with my code?
XML snippet
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:background="#drawable/background2"
tools:context="com.jack.cheng.buddhistcopy.Activity1">
<ScrollView
android:layout_width="300dp"
android:layout_height="300dp"
android:id="#+id/scrollView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:fillViewport="true"
android:isScrollContainer="true"
android:saveEnabled="true">
<TableLayout
android:id="#+id/sutra"
android:layout_width="295dp"
android:layout_height="295dp"
android:orientation="vertical"
>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:text="Test"
android:layout_width="10dp"
android:layout_height="10dp"
>
</EditText>
</TableRow>
</TableLayout>
</ScrollView>
</RelativeLayout>
Did you try adding the following attribute to the ScrollView?
xmlns:android="http://schemas.android.com/apk/res/android"
Try using:
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TestText"
/>
You might want to use the conditions : wrap_content, fill_parent or match_parent as using these allows your view elements to adjust accordingly to the device screen which can vary.
Also you might want to add an android:id="#id/myIdentifier" to that EditText so you can link it to whatever process you have going on in your app.

Android Studios - Adjusting VideoView Size in Layout Editor

I've only ever seen questions asking how to full screen the VideoView but what I'm trying to do is have a video playing as only a part of the activity, with some additional elements on the page. How would I go about doing that? It doesn't seem that I have control of the size of the VideoView, I can only shift it around in the designer.
Edit: Additional Info
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.MyActivity">
<Button
Default button Stuff
/>
<TextView
Default textview stuff
/>
<VideoView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/videoView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android: />
</RelativeLayout>
As far as ideal proportions go, maybe something like 500 x 400 dp? I can play with numbers after I understand the process.
If I understand you correctly, this is something that you'd want:
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.MyActivity">
<LinearLayout
android:id="#+id/componentLayout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:text="Button"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
<TextView
android:text="This is a placeholder text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<VideoView
android:layout_marginTop="20dp"
android:layout_below="#+id/componentLayout"
android:layout_width="300dp"
android:layout_height="400dp"
android:id="#+id/videoView"
android:layout_centerHorizontal="true" />
</RelativeLayout>
You can define the android:layout_width and android:layout_height attributes as you wish. However, they can not exceed the height or width of the parent layout.
Result:
Width: 300dp, Height: 400dp

Make scrollview in layout (crash)

I'm trying to make a screen scrollable with scroll view but my application keeps crashing.
What I've done is to replace RelativeLayout by ScrollView, but it doesn't work.
I need your help with this. Here is the code of the screen:
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="0dp"
android:background="#drawable/background01"
tools:context=".MainActivity"
android:id="#+id/relativeLayout">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/id"
android:background="#drawable/lightcontainer"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:weightSum="1"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:layout_marginBottom="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/mainTitle1"
android:id="#+id/textView"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:textSize="20sp"
android:textColor="#ffffff"
android:shadowColor="#000000"
android:shadowRadius="1.5"
android:shadowDx="2"
android:shadowDy="2"/>
</LinearLayout>
what you are trying to do is not an scrollable view it's just a relative layout. Try to put your code inside a ScrollView component, like this:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<!-- PUT YOUR CODE HERE -->
</ScrollView>
Make sure you close all tags correctly as well (your relative layout is not closed).
<RelativeLayout>
Content
</RelativeLayout> <-- This closing tag is always necessary

Android minus Margin/Padding

I work with android, I want to draw design like this
There are two LinearLayuots ( blue and white ), I want add picture their borders, I have tryied to use minus margin but not work
Can Anybody help me?
You'd want something like this:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/firstRow"
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="#013032"
android:orientation="horizontal"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="#ff3e7730"
android:layout_below="#+id/firstRow"/>
<ImageView
android:layout_alignParentRight="true"
android:layout_marginRight="30dp"
android:layout_width="140dp"
android:layout_height="140dp"/>
</RelativeLayout>
you can use a RelativeLayout for your layout's parent and then add two LinearLayout and one ImageView or Button. and set your Button (or ImageView,etc) to centerVertical and alignParentLeft and give some marginLeft to it!
<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"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.neo.myapplication.MyActivity">
<LinearLayout
android:id="#+id/aboveLayout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#android:color/darker_gray"
></LinearLayout>
<LinearLayout
android:layout_below="#+id/aboveLayout"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#android:color/holo_green_dark"></LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:src="#drawable/ic_launcher"/>
</RelativeLayout>

Categories

Resources