How to create your own controls in Android Studio - android

I looked at the official tutorial but I just don't get it.
This is my class:
public class mycontrol extends GridLayout {
public mycontrol(Context context, AttributeSet attrs) {
super(context, attrs);
}}
This is my res/layout/mycontrol.xml:
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="60dp"
android:columnCount="4"
android:rowCount="2"
android:background="#drawable/cellshapeownstatus"
android:paddingTop="5dp"
android:id="#+id/my_status_id">
<TextView
android:textColor="#FFFFFF"
android:layout_column="1"
android:layout_row="0"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="doing stuff"
android:id="#+id/myOwnName" /></GridLayout>
This is my res/layout/activity_main.xml, where I want to show mycontrol:
<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:paddingLeft="2dp"
android:paddingRight="2dp"
tools:context=".MainActivity"
android:orientation="vertical"
android:background="#0A3E61"
android:id="#+id/activity_main_id">
<com.example.test.mycontrol
android:id="#+id/my_status"
android:layout_width="fill_parent"
android:layout_height="70dp"/></LinearLayout>
Nothing shows up in the Designer Preview. I can build without errors, but it instantly crashes when I try to run it on my Phone.

Simply use 'include'
<include
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="#layout/mycontrol"
/>

You don't need to extend GridLayout and you forgot to inflate your xml:
public class MyControl extends FrameLayout {
public MyControl(Context context, AttributeSet attrs) {
super(context, attrs);
inflate(context, R.layout.mycontrol, this);
}
}
layout:
<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:paddingLeft="2dp"
android:paddingRight="2dp"
tools:context=".MainActivity"
android:orientation="vertical"
android:background="#0A3E61"
android:id="#+id/activity_main_id">
<com.example.test.MyControl
android:id="#+id/my_status"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

Related

Webview not working correctly in nestedscrollview

I have some content in NestedScrollView and under this content i have WebView with height wrap_content. When i scroll NestedScrollView scroll on element inside WebView not work.
activity_main.xml
<androidx.constraintlayout.widget.ConstraintLayout 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">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#drawable/ic_launcher_foreground" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#drawable/ic_launcher_foreground" />
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
<WebView
android:id="#+id/widgets"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
WebView inside NestedScrollView (not work)
WebView without NestedScrollView
public class CustomView extends WebView {
public CustomView(Context context) {
super(context);
}
public CustomView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
#Override
public boolean onTouchEvent(MotionEvent event){
requestDisallowInterceptTouchEvent(true);
return super.onTouchEvent(event);
}
}
<com.abc.customer.android.widgets.CustomView
android:id="#+id/my_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
Structure looks like
<?xml version="1.0" encoding="utf-8"?>
<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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.main.view.MainActivity">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="300dp"
app:srcCompat="#drawable/abc_vector_test" />
<ImageView
android:layout_width="match_parent"
android:layout_height="100dp"
app:srcCompat="#drawable/abc_vector_test" />
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<ImageView
android:layout_width="match_parent"
android:layout_height="300dp"
app:srcCompat="#drawable/abc_vector_test" />
<ImageView
android:layout_width="match_parent"
android:layout_height="100dp"
app:srcCompat="#drawable/abc_vector_test" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</RelativeLayout>
in backend
private lateinit var webView: WebView
webView = findViewById(R.id.webview)
webView.settings.setJavaScriptEnabled(true)
webView.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
view?.loadUrl(url)
return true
}
}
webView.loadUrl("https://www.google.co.in/")

When Rendering FontAwesome Icons on Android, some Icons are rendered with Overlapping Chinese Characters

As part of one of the views in my app, I have a place where users can choose to navigate to one of many other pages depending on which icon is tapped. To render these icons, we are using a combination of custom-designed icons and the FontAwesome icon library.
However, on some devices, such as the Samsung Galaxy S7, some of the icons do not always render as expected. In particular one of them renders in an overlapping fashion with a Chinese character. So far we have been unable to figure out why this is happening, so any help would be greatly appreciated.
We are using Xamarin Android and MvvmCross to create our app.
Some of the view code for the main layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
style="#style/RelativeLayoutPageStyle"
android:background="#color/white">
<RelativeLayout
style="#style/RelativeHeader"
android:id="#+id/linearLayout1">
<FontAwesomeIcon
android:id="#+id/flag"
android:layout_alignParentLeft="true"
style="#style/MenuButton" />
<ImageView
android:id="#+id/Header"
style="#style/HeaderLogo"
android:layout_centerInParent="true"
android:src="#drawable/TitleWithIcon" />
<FontAwesomeIcon
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ViewFailedRecordButton"
android:layout_toLeftOf="#+id/ViewAssignmentsButton"
android:layout_toRightOf="#id/Header"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:textColor="#b8860b"
android:text="\uf06a"
android:textSize="16dp"
local:MvxBind="Click ViewFailedRecordsCommand;Visibility BooleanVisibility(FailedRecordsDetected)" />
<FontAwesomeIcon
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ViewAssignmentsButton"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="\uf022"
android:textSize="16dp"
local:MvxBind="Click ViewAssignmentCommand;Visibility BooleanVisibility(HaveAssignmentsForUser);TextColor AssignmentButtonColor, Converter=NativeColor" />
</RelativeLayout>
<LinearLayout
style="#style/CollectionViewHeader"
android:id="#+id/collectionViewHeader"
android:layout_below="#id/linearLayout1"
local:MvxBind="BackgroundColor HeaderBackgroundColor, Converter=NativeColor">
<TextView
android:layout_centerInParent="true"
style="#style/TextViewHeaderResponsive"
local:MvxBind="Text HeaderText" />
</LinearLayout>
<GridView
android:id="#+id/gridView"
android:layout_below="#id/collectionViewHeader"
android:layout_above="#+id/collectionViewFooter"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="2" />
<LinearLayout
style="#style/CollectionViewFooter"
android:id="#id/collectionViewFooter"
android:layout_alignParentBottom="true"
local:MvxBind="Visibility HideOnEmptyText(FooterText);BackgroundColor FooterBackgroundColor, Converter=NativeColor;Click FooterClickCommand">
<TextView
android:layout_centerInParent="true"
style="#style/StatusBarFooterTextView"
local:MvxBind="Text FooterText" />
</LinearLayout>
</RelativeLayout>
<MvxListView
android:id="#+id/left_drawer"
style="#style/Menu"
local:MvxItemTemplate="#layout/drawerlistitem"
local:MvxBind="ItemsSource NavigationCellModels" />
</android.support.v4.widget.DrawerLayout>
View for the Template used in the above GridView:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
local:MvxBind="Click ClickCommand">
<RelativeLayout
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center">
<FontAwesomeIcon
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="100dp"
android:layout_gravity="center"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
local:MvxBind="Text RecordableDataTypeToIcon(RecordableDataType);Visibility IsRecordableDataTypeFontAwesome(RecordableDataType);TextColor Color, Converter=NativeColor" />
<CbtGlyphIcon
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="100dp"
android:layout_gravity="center"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
local:MvxBind="Text RecordableDataTypeToIcon(RecordableDataType);Visibility IsRecordableDataTypeCbtGlyphValueConverter(RecordableDataType);TextColor Color, Converter=NativeColor" />
</RelativeLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:textSize="20sp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="10dp"
android:maxLines="2"
android:ellipsize="end"
local:MvxBind="Text Title;TextColor Color, Converter=NativeColor" />
</LinearLayout>
Code for the FontAwesomeIcon Class:
public class FontAwesomeIcon : TextView
{
private Context _context;
protected FontAwesomeIcon(IntPtr javaReference, JniHandleOwnership transfer)
: base(javaReference, transfer)
{
Initialise(null, null);
}
public FontAwesomeIcon(Context context)
: base(context)
{
Initialise(context, null);
}
public FontAwesomeIcon(Context context, IAttributeSet attrs)
: base(context, attrs)
{
Initialise(context, attrs);
}
public FontAwesomeIcon(Context context, IAttributeSet attrs, int defStyle)
: base(context, attrs, defStyle)
{
Initialise(context, attrs);
}
private void Initialise(Context context, IAttributeSet attrs)
{
_context = context ?? Application.Context;
Typeface = Android.Graphics.Typeface.CreateFromAsset(context.Assets, "FontAwesome.otf");
}
}
Finally here's a screenshot of what I'm seeing:

GridLayout with SquareRelativeLayout item

I succeed to create a SquareRelativeLayout. Then I use this CustomLayout as one grid item of a GridLayout. I have 5 items for now (but it can be variable). For the first row, everything is fine. My item has a size of 400*400 but for the second row I have something like 400*429. I think my issue come from above, indeed I use a LinearLayout and my GridLayout has a height of layout:weight 0.50. Here is my current layout :
<?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/mainContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="MainActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#66000000">
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="0dp" ... />
<android.support.v7.widget.GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:grid="http://schemas.android.com/apk/res-auto"
android:id="#+id/droparea"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.50"
grid:columnCount="3"
grid:orientation="horizontal">
<SquareRelativeLayout
android:id="#+id/relativelayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
grid:layout_columnWeight="1"
grid:layout_gravity="fill"
android:background="#drawable/round_layout"
android:gravity="center_vertical|center_horizontal">
...
</SquareRelativeLayout>
<SquareRelativeLayout
android:id="#+id/relativelayout2"
android:layout_width="0dp"
android:layout_height="wrap_content"
grid:layout_columnWeight="1"
grid:layout_gravity="fill"
android:background="#drawable/round_layout"
android:gravity="center_vertical|center_horizontal">
...
</SquareRelativeLayout>
<SquareRelativeLayout
android:id="#+id/relativelayout3"
android:layout_width="0dp"
android:layout_height="wrap_content"
grid:layout_columnWeight="1"
grid:layout_gravity="fill"
android:background="#drawable/round_layout"
android:gravity="center_vertical|center_horizontal">
...
</SquareRelativeLayout>
<SquareRelativeLayout
android:id="#+id/relativelayout4"
android:layout_width="0dp"
android:layout_height="wrap_content"
grid:layout_columnWeight="1"
grid:layout_gravity="fill"
android:background="#drawable/round_layout"
android:gravity="center_vertical|center_horizontal">
....
</SquareRelativeLayout>
<SquareRelativeLayout
android:id="#+id/relativelayout5"
android:layout_width="0dp"
android:layout_height="wrap_content"
grid:layout_columnWeight="1"
grid:layout_gravity="fill"
android:background="#drawable/round_layout"
android:gravity="center_vertical|center_horizontal">
...
</SquareRelativeLayout>
</android.support.v7.widget.GridLayout>
<include layout="#layout/draggable_linearlayout"/>
</LinearLayout>
</RelativeLayout>
And here is the code of my SquareRelativeLayout :
import android.content.Context;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
public class SquareRelativeLayout extends RelativeLayout {
public SquareRelativeLayout(Context context) {
super(context);
}
public SquareRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, widthMeasureSpec);
}
}
So I want to be able to set a variable height for my GridLayout but to keep squared items. Is it possible to let GridLayout fill the 29dp ? Did I miss an attribute ? If you can help me, don't hesitate :)
It was simple, but yesterday I didn't think about it. You just need to use a ParentLayout for the GridLayout and then set to the layout_height of the GridLayout the attribute wrap_content and that's it :)

findViewById returns null - why?

I have created a custom view Game4 that extends LinearLayout. When I tried finding them, it field and returned null (and then nullPointerException and then crash/!!)
This is activity_play_game.xml:
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.sortthegraph.PlayGameActivity"
tools:ignore="MergeRootFrame" >
<LinearLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<com.example.sortthegraph.Game_4 // A custom View extends LinearLayout
android:id="#+id/game4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
</com.example.sortthegraph.Game_4>
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="#000000" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
This is my OnCreate function:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play_game);
tempGame = (Game_4) findViewById(R.id.game4); // ?? Why null ??
This is Game_4 constructors:
public class Game_4 extends LinearLayout {
public Game_4(Context context, AttributeSet attrs) {
this(context);
}
public Game_4(Context context) {
super(context);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.game_4_layout, this, true);
this.setWillNotDraw(false);
}
The game_4_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="20dp"
android:paddingBottom="25dp"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:gravity="center" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<View android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1" />
<com.example.sortthegraph.BackButton
android:id="#+id/backButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp" >
</com.example.sortthegraph.BackButton>
<View android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="20dip"
android:layout_marginTop="20dip" >
<com.example.sortthegraph.BackButton
android:id="#+id/backButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</com.example.sortthegraph.BackButton>
<View
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1" />
<com.example.sortthegraph.BackButton
android:id="#+id/backButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</com.example.sortthegraph.BackButton>
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<View android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1" />
<com.example.sortthegraph.BackButton
android:id="#+id/backButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" >
</com.example.sortthegraph.BackButton>
<View android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1" />
</TableRow>
public Game_4(Context context, AttributeSet attrs) {
this(context);
}
You need to pass the attrs to the super constructor, e.g.
super(context, attrs);
Otherwise the attributes consumed by the superclass such as android:id are lost.
You can do your custom init in this two-arg constructor and call it from the 1-arg constructor as well:
public Game_4(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.game_4_layout, this, true);
this.setWillNotDraw(false);
}
public Game_4(Context context) {
this(context, null);
}
Game_4 has not been imported properly. Also in layout , press CTRL and take the cursor to com.example.sortthegraph.Game_4 and click to go to the corresponding class. If it does not direct to that corresponding class, then there may be some issue.

calendarview stops scrolling when nested in scrollview in android

I have nested calendarview in ScrollView . My problem begins when height of view increases.
I can scroll calendar months vertically but when scrollview scrollbar comes it does not let scroll calendar. Instead of scrolling calendar the whole view scroll up or down.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout android:orientation="vertical" android:id="#+id/ReminderLayout"
android:layout_width="fill_parent" android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/TaskName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textCapWords"
android:singleLine="true"
android:textSize="26.0sp" />
<View
android:id="#+id/seperator"
android:layout_width="fill_parent"
android:layout_height="1dip" />
<TextView
android:id="#+id/lblNotes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Notes" />
<EditText
android:id="#+id/TaskNotes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:textSize="26.0sp" />
<View
android:id="#+id/seperator"
android:layout_width="fill_parent"
android:layout_height="1dip" />
<TextView
android:id="#+id/lblReminder"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Reminder" />
</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content">"
<CalendarView
android:id="#+id/calendarReminder"
android:layout_width="fill_parent"
android:layout_height="250dp"
android:scrollbars="vertical"
android:isScrollContainer="true" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TimePicker
android:id="#+id/timePickerReminder"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:gravity="center" />
</LinearLayout>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="wrap_content" >
<View android:id="#+id/seperator" android:layout_width="fill_parent" android:layout_height="1dip"/>
<TextView android:id="#+id/ReminderTime" android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="On Time" android:paddingLeft="20dip"/>
<View android:id="#+id/seperator" android:layout_width="fill_parent" android:layout_height="1dip"/>
<TextView android:id="#+id/Recurring" android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Only Once" android:paddingLeft="20dip"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
I've found answer to this problem here:
https://stackoverflow.com/a/9687545
Basically you need to implement custom CalendarView and override onInterceptTouchEvent method.
I did it as following:
package com.example.app.views;
public class CalendarViewScrollable extends CalendarView {
public CalendarViewScrollable(Context context) {
super(context);
}
public CalendarViewScrollable(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CalendarViewScrollable(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
#Override
public boolean onInterceptTouchEvent(MotionEvent ev)
{
if (ev.getActionMasked() == MotionEvent.ACTION_DOWN)
{
ViewParent p = getParent();
if (p != null)
p.requestDisallowInterceptTouchEvent(true);
}
return false;
}
}
Then just use this view in XML layout file:
<com.example.app.views.CalendarViewScrollable
android:id="#+id/datePicker1"
android:layout_width="400dp"
android:layout_height="400dp"
/>
Here's one solution, you can implement a custom ScrollView which will only intercept verticale swipe.
#Override
public boolean onInterceptTouchEvent(MotionEvent ev) {...}
"onInterceptTouchEvent" will return false for horizontal swipe, so horizontal swipe will be enable for the CalendarView.
You can read more about this heree : https://stackoverflow.com/a/2655740/5158173

Categories

Resources