How to repeat an image while you are scrolling? - android

How can i repeat an image on background? I'm trying to put an image (a notebook sheet) into a scrollview. But i can't figure out how to make it. Can you give me an example?
I'm new at android programming.
PD:Sorry for my bad english.

If i unterstand you correctly, This way help you.
Import a drawable image like that "img_blue_gray.png"
Then create a xml file in Drawable Folder
repeating.xml
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/img_blue_gray"
android:tileMode="repeat"
/>
For example: usage in Layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parrent"
android:layout_height="match_parrent"
android:orientation="vertical">
<ScrollView
android:id="#+id/scrollView2"
android:layout_width="match_parrent"
android:layout_height="match_parrent"
android:layout_gravity="center_horizontal"
android:background="#drawable/repeating.xml">
/* Your other views */
</ScrollView>
</LinearLayout>

Related

When I use a ScrollView with AndroidStudio, everything in my layout gets shifted down

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:context=".view.characterlist.HaruActivity"
android:background="#drawable/harubackgound"
>
...
</RelativeLayout>
Here is a picture of the screen without ScrollView :
https://media.discordapp.net/attachments/473468257626488852/722442283181539409/unknown.png
And here with :
https://media.discordapp.net/attachments/473468257626488852/722441710067777617/unknown.png
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".view.characterlist.HaruActivity"
android:background="#drawable/harubackgound"
>
...
</RelativeLayout>
</ScrollView>
Could someone help me ? Ty
try setting the image as a background, so you would add:
android:background = "#drawable/...
in the parent relative layout.
I believe that all the textviews are going down because the image is currently in an imageview, and if you want to overlay textview over the image, then you need to set image as the background.

Drop shadow renders without transparency

In this project (feature/drop-shadow branch) I am trying to add a drop shadow above a view container. Therefore, I defined the following shape (drawable/shadow_above):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#20000000"
android:endColor="#android:color/transparent"
android:angle="90">
</gradient>
</shape>
This is then used in the layout file (container_infos.xml) as follows:
<View
android:background="#drawable/shadow_above"
android:layout_width="match_parent"
android:layout_height="4dp"/>
The screenshot shows the result. For some reason the drop shadow looks awful. There is no transparency. What am I doing wrong? Feel free to send a pull request to my open source project.
Solution using a RelativeLayout
I managed to get the desired result by using a RelativeLayout in fragment_map.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context=".ui.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<FrameLayout
android:id="#+id/map_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:background="#android:color/holo_purple"/>
<View
android:background="#drawable/shadow_above"
android:layout_alignBottom="#id/map_container"
android:layout_width="match_parent"
android:layout_height="4dp"/>
</RelativeLayout>
<include
layout="#layout/container_infos"/>
</LinearLayout>
There might be room for optimization.
as far as I see you should give map_container_infos_layout a negative top margin of the size 4dp and it should look better

android how to code dialog layout

I want to code this dialog layout: http://fooh.pl/pokaz/348687655.png
Green containner is in orange container. At the top of the dialogue is TextView. In the upper right corner is a button.
I know the types of layouts, but I failed.
Can anyone help me? Please.
Here you go:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/rounded_orange">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="8dp"
android:text="Text"/>
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="32dp"
android:background="#drawable/rounded_green">
</RelativeLayout>
</RelativeLayout>
Where the drawables (only green shown here) are laid out like this:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#0F0"/>
<corners android:radius="16dp"/>
</shape>
If you need help applying the custom layout.xml file to your dialog, read up on 'Creating a Custom Dialog' in the official docs of Dialog.
Here's a link to the documentation with good examples or how to create a dialog fragment based on a layout.
And here is a good SO answer that shows how to inflate a layout for use in a dialog fragment.

Need pattern background and over it need to place an image

I have a pattern-based background drawable:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/back"
android:tileMode="repeat"/>
On this activity I'm displaying a background-pattern:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/back"
android:scrollbars="vertical"
>
</LinearLayout
Have a result like:
http://img525.imageshack.us/img525/2257/63411225.jpg
Need result:
http://img811.imageshack.us/img811/4894/12572985.jpg
You are not including the necessary code (the layout that has both your background, and the image).
The problem has nothing to do with your background, and (probably) everything to do with how you are actually laying out your image.
If this is you complete code, you need to add a attribute, which would include you Image.

Integrating Ads in a Game

i have a 2D game which has my custom ViewPanel which handles all the drawings (i don't have android Button elements, all my game controls are painted/handled internally).
this is my main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</LinearLayout>
and this is my activity's onCreate() main code:
viewPanel = new ViewPanel(this);
setContentView(viewPanel);
from this point my ViewPanel handles all the drawings/events.
Now,
i want to integrate Ads (Mobclix), and this is how i do it:
setContentView(R.layout.mobclix_advertising_view);
Mobclix.onCreate(this);
adview_banner = (MobclixMMABannerXLAdView) findViewById(R.id.advertising_banner_view);
adview_banner.addMobclixAdViewListener(this);
adview_banner.setRefreshTime(30000);
adview_banner.getAd();
HOWEVER! it seems i can either setContentView on my ViewPanel OR on "advertising_banner_view" not both. So basically either i see my game drawing OR the advertising bar.
How can i see them both?
Try this:
my_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</FrameLayout>
Now just use my_layout as you main layout, and call addView twice on it, once with your ViewPanel and once with your AdView. You can set the gravity of the adview to float it where ever you want on the screen.
You can do this:
game.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<com.package.ViewPanel />
<com.package.MobclixMMABannerXLAdView />
</LinearLayout>
in your code:
setContentView(R.layout.game);
than you can use findviewbyid to get those views.

Categories

Resources