Dr.jacky
Dr.jacky

Reputation: 3547

Is a nine patched image shrinkable?

I have a nine patch image for background. It's 802px x 286px (2px in both w&h added automatically By 9patchtools).

The main.xml looks like:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/crown"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/crown">
<ListView
    android:id = "@+id/mainmenulist"
    style="@style/MainMenuList"
    android:dividerHeight="2.5dp"/>
</RelativeLayout>

The styles.xml looks like:

<resources
xmlns:android="http://schemas.android.com/apk/res/android">
<style name="MainMenuList">
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">fill_parent</item>
    <item name="android:cacheColorHint">@android:color/transparent</item>
    <item name="android:listSelector">@android:color/transparent</item>
    <item name="android:divider">@null</item>
    <item name="android:gravity">right</item>
</style>
<style name="MainMenuRow">
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textColor">#000000</item>
    <item name="android:gravity">right|center</item>
    <item name="android:padding">0dp</item>
</style>
</resources>

The themes.xml in values folder:

<resources
xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="android:Theme.Light.NoTitleBar.Fullscreen">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowBackground">@color/mycustomblue</item>
</style>
</resources>

mpart of manifest.xml:

<application android:label="@string/app_name"
    android:icon="@drawable/ic_launcher"
    android:theme="@style/AppTheme">

It's row image:

it's background(crown) image:

The output should be like this:

But it looks like this:

My questions are:

  1. My ninepatched image for background is 802x286. My device is galaxy S3 with android 4.0.4 and 720x1280(WxH). Does image can scale down to fit width? (in other words if I use a 9patch image 100x100 for a device that is 200x200 , we knows its good and scale up. But the question is here that if use for device that is 50x50, what's happen?)

  2. Why is my application not fullscreen?

  3. Why is the sample text not middle and right aligned?

  4. Why is the row image scale up undue?

Upvotes: 3

Views: 1253

Answers (1)

Ponyets
Ponyets

Reputation: 336

  1. I think the nine ninepatched image would not be shrunk or stretched when you don't tell the part to scale in horizontal.The image only be scaled from just those 2pxes, so the smallest width is 798px, you may need a smaller image.

  2. android:windowNoTitle control the titlebar whether to display, not the status bar. Title bar is part of you activity, but status bar is part of system. what you need maybe android:windowFullscreen

    <!-- Variant of {@link #Theme} with no title bar -->
    <style name="Theme.NoTitleBar">
        <item name="android:windowNoTitle">true</item>
    </style>
    
    <!-- Variant of {@link #Theme} that has no title bar and no status bar -->
    <style name="Theme.NoTitleBar.Fullscreen">
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
    </style>
    
  3. Right and center are conflicting, you may use right|center_vertical. Do you use a single TextView as list item ,can you provide you list item layout

  4. This may be caused by android:listPreferredItemHeight property in theme. Use an explicit layout_height may fix this problem.

Upvotes: 3

Related Questions