I have a RelativeLayout where I Inflate the current view:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#drawable/selected_background"
android:clipChildren="false"
android:clipToPadding="false"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:translationX="-5dp"
android:translationY="-5dp"
android:background="#drawable/selected_edge_circle"
android:layout_width="25dp"
android:layout_height="25dp"/>
</LinearLayout>
selected_background is a drawable:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#android:color/holo_red_dark"/>
<stroke android:width="3dp" android:color="#4fa5d5"/>
</shape>
and the selected_edge_circle:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<size android:width="25dp" android:height="25dp"/>
<solid android:width="3dp" android:color="#4fa5d5"/>
<stroke android:width="3dp" android:color="#4fa5d5"/>
</shape>
I'm getting this result:
As you can see the circle is cut-of, although I ahve specified not to clip it. I want to show a circle on the top left corner that looks like this:
I don't want to wrap this Layout in another container and set a padding or a margin, I want, no matter what, overflow the top left circle. Any ideas who this can be achieved? Thanks!
I don't know if it's the way you want it. I believe it is a way of doing.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:clipChildren="false"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:background="#drawable/selected_background"
android:clipChildren="false"
android:clipToPadding="false"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp">
<View
android:translationX="-5dp"
android:translationY="-5dp"
android:background="#drawable/selected_edge_circle"
android:layout_width="25dp"
android:layout_height="25dp"/>
</LinearLayout>
</RelativeLayout>
Related
This is the problem scenario:
I have an Activity including a ScrollView,
ScrollView has only one LinearLayout as a child and the LinearLayout has one TextView.
The XML file is here:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bubble_shape"
android:text="#string/TestLargeText"/>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
and the "bubble_shape" drawable is here:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:bottomLeftRadius="15dp"
android:bottomRightRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp"/>
<padding
android:bottom="12dp"
android:left="12dp"
android:right="12dp"
android:top="12dp"/>
<stroke
android:width="8dp"
android:color="#ff00ff"/>
</shape>
I have a large text in the TextView and here is the problem:
when the TextView has large text the background shape is not showing. You can see the problem in the pictures below:
how can I solve the problem?
I solved your problem in two ways .
1- set "bubble_shape" to your HorizontalScrollView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bubble_shape">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/TestLargeText" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
2- or just change corners tag in your "bubble_shape" like this :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="15dp" />
<padding
android:bottom="12dp"
android:left="12dp"
android:right="12dp"
android:top="12dp" />
<stroke
android:width="8dp"
android:color="#ff00ff" />
</shape>
I have a fragment shown on top of another with a transparent background, How can I remove this white space behind the blue drawable?
this is my Drawable
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:bottomLeftRadius="0dp"
android:bottomRightRadius="0dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp" />
<solid android:color="#android:color/holo_blue_light" />
</shape>
</item>
</selector>
and this is the fragment
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="#android:color/transparent"
android:clickable="true"
android:orientation="vertical"
android:layout_height="match_parent"
android:weightSum="2.2"
tools:context=".ui.main.signup.IdModeFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1.2"
android:background="#color/black_transparent_60"
android:layout_height="0dp"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:background="#drawable/id_mode_fragment_round_background"
android:padding="#dimen/app_padding"
android:weightSum="6"
android:layout_height="0dp">
Thanks for any help!
Shape Drawable: avatar_mask.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:innerRadius="0dp"
android:thicknessRatio="2">
<solid android:color="#android:color/transparent" />
<stroke
android:width="3dp"
android:color="#color/mask_color" />
</shape>
Layout
<FrameLayout
android:layout_width="#dimen/avatar_size"
android:layout_height="#dimen/avatar_size"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
<ImageView
android:id="#+id/avatar"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="#+id/avatar_mask"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/avatar_mask"/>
</FrameLayout>
In ADT's Graphic Layout, it looks OK:
Image 1
while on real device, it looks like this, this avatar_mask ring is displayed as a line, not stretched to parent size:
Image 2
good day.
today i was encounted this next problem:
i have listview:
<ListView
tools:listitem="#layout/list_view_item"
android:listSelector="#android:color/transparent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:dividerHeight="0dp"
android:divider="#color/transparent"
android:cacheColorHint="#color/transparent"
android:id="#+id/items"/>
where list_view_item is:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/listview_item_background">
...
</LinearLayout>
and listview_item_background next:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle">
<solid android:color="#color/black" />
<padding
android:right="1dp"
android:top="1dp"
android:bottom="1dp"
android:left="1dp"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#color/green"/>
</shape>
</item>
</layer-list>
now then i run my app i see next:
as you can see between adjacent items horizontal border are same with vertical border, but i was expected double-bordered
then i try to set listview divider to 1dp. as expected i have three-bordered result
then i test my background drawable not in listview, but simple three linearlayout. i have expected result with double-border...
<LinearLayout
android:orientation="vertical"
android:padding="10dp"
android:layout_width="100dp"
android:layout_height="100dp">
<View
android:layout_width="50dp"
android:layout_height="25dp"
android:background="#drawable/listview_item_background"/>
<View
android:layout_width="50dp"
android:layout_height="25dp"
android:background="#drawable/listview_item_background"/>
<View
android:layout_width="50dp"
android:layout_height="25dp"
android:background="#drawable/listview_item_background"/>
</LinearLayout>
but in listview i still have one border.
how i can create listview with horizontal double-border on adjacent item?
ok, i didn't fix it, but i find workaround (but in my opinion it is a cruch):
in my drawable i set bottom padding form 1dp to 2 dp
I'm trying to code a simple MapActivity which uses the following layout (only contains the mapview for the moment, as I plan to add share the screen with a ListView in the future) :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="200dip"
android:enabled="true"
android:clickable="true"
android:apiKey="mykey"
android:layout_alignParentBottom="true" />
</RelativeLayout>
I have applied a simple shape to the mapview in order to have round corners and a stroke :
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>
<stroke android:width="3dp"
android:color="#color/bordure_tables" />
</shape>
I use the following to apply the shape :
mapView.setBackgroundResource(R.layout.map);
Problem is that it does not have any effect and I can't see my rounded corners, nor the stroke.
Just wrote a tutorial to have rounded corners on a MapView it's done programmatically so should scale well to all devices:
http://www.anddev.org/novice-tutorials-f8/rounded-corners-map-view-t56908.html
Once you have added the custom view class you can just instantiate a rounded mapview like so:
<com.blundell.tut.ui.widget.RoundedMapView
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
Have you tried assigning it a padding?
<padding
android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp" />
So your strokes and radius should be visible.
So I've achieved this affect by doing following: I've created a 9-patch drawable called round_corners and placed it in my drawable folder, then I use following xml to plot the map:
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">/
<com.google.android.maps.MapView
android:id="#+id/center_map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="your_key"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/round_corners"
></LinearLayout>
</FrameLayout>
I was able to achieve this creating a rounded drawable like this:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#android:color/transparent" />
<stroke android:width="10dp" android:color="#color/color_gray5_eeeeee" />
<corners android:radius="10px" />
</shape>
then using a linear layout and a margin of the same size of the drawable stroke width, like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background_gray_rectangle_rounded_corners"
android:orientation="vertical">
<com.google.android.gms.maps.MapView
android:id="#+id/map_details_map_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:clickable="true"
android:enabled="true" />
</LinearLayout>
Just put the Mapview into a CardView
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="100dp"
android:elevation="0dp"
app:cardCornerRadius="5dp">
<com.google.android.gms.maps.MapView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v7.widget.CardView>