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.
Related
I created a new custom view that looks like this
public class SearchCategoryPanel extends RelativeLayout {
private boolean hasRetrieved = false;
private GridLayout categoryContainer;
private TextView scpLoadingText;
public static final int HEIGHT = 360;
private ArrayList<OnCategoryItemClickListener> onCategoryItemClickListeners = new ArrayList<OnCategoryItemClickListener>();
public SearchCategoryPanel(Context context) {
super(context);
init();
}
public SearchCategoryPanel(Context context, AttributeSet attrs) {
super(context, attrs);
Log.i(SearchCategoryPanel.class.getSimpleName(), this.getTop() + "");
init();
}
public SearchCategoryPanel(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public void init() {
inflate(getContext(), R.layout.search_category_panel, this);
this.scpLoadingText = (TextView) findViewById(R.id.sCategoryPanelLoadingText);
this.categoryContainer = (GridLayout) findViewById(R.id.sCategoryContainer);
this.setVisibility(View.GONE);
}
public void show() {
this.setVisibility(View.VISIBLE);
}
public void hide() {
this.setVisibility(View.GONE);
}
public void setProcessing(boolean on) {
if(!on) {
this.scpLoadingText.setVisibility(View.GONE);
} else {
this.scpLoadingText.setVisibility(View.VISIBLE);
}
}
public void addCategoryItemUsingVo(CategoryVo categoryVo) {
CategoryItem item = new CategoryItem(getContext());
item.setCategoryVo(categoryVo);
item.setOnItemClickListener(new CategoryItem.OnClickListener() {
#Override
public void onClick(CategoryVo categoryVo) {
triggerOnCategoryItemClickListener(categoryVo);
}
});
this.categoryContainer.addView(item);
}
public void removeAllItems() {
this.categoryContainer.removeAllViews();
}
public boolean hasRetrieved() {
return hasRetrieved;
}
public interface OnCategoryItemClickListener {
public void onClick(CategoryVo categoryVo);
}
public void setOnCategoryItemClickListener(OnCategoryItemClickListener listener) {
this.onCategoryItemClickListeners.add(listener);
}
private void triggerOnCategoryItemClickListener(CategoryVo vo) {
for(OnCategoryItemClickListener listener : onCategoryItemClickListeners ) {
listener.onClick(vo);
}
}
}
Then, I try to call the getHitRect
Rect rectF = new Rect();
searchCategoryPanel.getHitRect(rectF);
Log.i(ARModeActivity.class.getSimpleName(), "Rect: " + rectF.toString());
The log returns strange value: Rect: Rect(0, 0 - 1920, 1164). this means the relative layout covers the whole screen which is not correct.
The SearchCategoryPanel xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#7F000000"
android:layout_alignParentBottom="true"
android:maxHeight="360dp"
android:layout_height="160dp">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Search Category"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="24dp"/>
<TextView
android:id="#+id/sCategoryPanelLoadingText"
android:layout_width="wrap_content"
android:textSize="24sp"
android:textColor="#android:color/white"
android:layout_height="match_parent"
android:text="Loading.."/>
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<GridLayout
android:id="#+id/sCategoryContainer"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content">
</GridLayout>
</HorizontalScrollView>
</LinearLayout>
</RelativeLayout>
The relative layout only has 360dp in height, andfull width (look at the xml). but it returns the wrong value. I have read about onMeasure and onSizeChanged, but nothing helped
Here How I call the search_category_panel 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:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
android:id="#+id/rootArMode"
tools:context="com.imav.ARModeActivity">
<RelativeLayout
android:id="#+id/rlInfoARMode"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:background="#7F000000"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:orientation="vertical"
android:layout_centerHorizontal="true"
android:gravity="center"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#FFF"
android:textSize="24sp"
android:text="Interaction Guide"/>
<LinearLayout
android:gravity="left"
android:layout_width="match_parent"
android:layout_marginBottom="4sp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textColor="#FFF"
android:textSize="18sp"
android:textStyle="bold"
android:text="Select: "/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textColor="#FFF"
android:textSize="16sp"
android:text="Tap on object with 1 finger "/>
</LinearLayout>
<LinearLayout
android:gravity="left"
android:layout_width="match_parent"
android:layout_marginBottom="4sp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textColor="#FFF"
android:textSize="18sp"
android:textStyle="bold"
android:text="Move: "/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textColor="#FFF"
android:textSize="16sp"
android:text="Touch and Drag Object with 1 finger "/>
</LinearLayout>
<LinearLayout
android:gravity="left"
android:layout_marginBottom="4sp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textColor="#FFF"
android:textSize="18sp"
android:textStyle="bold"
android:text="Rotate: "/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textColor="#FFF"
android:textSize="16sp"
android:text="Touch and drag object with 2 fingers "/>
</LinearLayout>
<LinearLayout
android:gravity="left"
android:layout_width="match_parent"
android:layout_marginBottom="4sp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textColor="#FFF"
android:textSize="18sp"
android:textStyle="bold"
android:text="Scale: "/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textColor="#FFF"
android:textSize="16sp"
android:text="Touch and pinch object with 2 fingers "/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<Button
android:id="#+id/btnCloseArMode"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="15dp"
android:background="#drawable/ic_clear_white_24dp" />
<RelativeLayout
android:id="#+id/rlOpenActionBar"
android:layout_width="55dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true">
<Button
android:id="#+id/btnOpenActionBar"
android:background="#drawable/ic_keyboard_backspace_white_24dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="55dp"
android:id="#+id/rlActionBar"
android:layout_height="match_parent"
android:visibility="gone"
android:background="#7F000000"
android:layout_alignParentRight="true">
<Button
android:id="#+id/btnInfoArMode"
android:layout_width="wrap_content"
android:background="#drawable/ic_error_white_24dp"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<Button
android:id="#+id/btnAddObjArMode"
android:layout_marginBottom="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_add_white_24dp"
android:layout_below="#+id/btnSaveSceneArMode" />
<Button
android:id="#+id/btnSaveSceneArMode"
android:layout_marginBottom="8dp"
android:layout_width="wrap_content"
android:background="#drawable/ic_add_a_photo_white_24dp"
android:layout_height="wrap_content" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:id="#+id/pbSaveSceneArMode"/>
<Button
android:id="#+id/btnShareARMode"
android:layout_width="wrap_content"
android:background="#drawable/ic_share_white_24dp"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<Button
android:id="#+id/btnTrashArMode"
android:layout_width="wrap_content"
android:background="#drawable/ic_delete_white_24dp"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
<com.imav.view.SearchCataloguePanel
android:id="#+id/searchCataloguePanelArMode"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</com.imav.view.SearchCataloguePanel>
<com.imav.view.SearchCategoryPanel
android:id="#+id/searchCategoryPanelArMode"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</com.imav.view.SearchCategoryPanel>
</RelativeLayout>
My first approach would be not to override the onMeasure() in your custom view SearchCategoryPanel. Because you are forcing a different dimension than the ones provided by the xml.
I have a created a custom view , in relative layout .
I'm able to align it in in center/left/right through xml but not
programatically
.
Custom View
public class HotspotView extends RelativeLayout {
public HotspotView(Context context) {
super(context);
init(context);
}
public HotspotView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public HotspotView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context);
}
private void init(Context context) {
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.hotspot_view, this);
}
}
Custom view xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/hotspot_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/tohome"
/>
</RelativeLayout>
Activity xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/black"
>
<VideoView
android:id="#+id/vv_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:clickable="true"
android:onClick="onclick"
android:visibility="gone" />
<ImageView
android:id="#+id/iv_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:contentDescription="#string/content_description"
android:onClick="onclick"
android:scaleType="fitXY"
android:visibility="gone"
/>
<ImageView
android:id="#+id/lv_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:contentDescription="#string/content_description"
android:onClick="onclick"
android:visibility="gone" />
<
<android.gesture.GestureOverlayView
android:id="#+id/gesture_area"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"
android:alpha="1.0"
android:background="#android:color/transparent"
android:gestureColor="#android:color/white"
android:onClick="onclick"
android:visibility="visible" />
<WebView
android:id="#+id/ticker_webview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:visibility="gone"></WebView>
<WebView
android:id="#+id/wv_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
android:onClick="onclick"
android:scaleType="fitXY"
android:visibility="gone"
/>
<ProgressBar
android:id="#+id/webview_progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:visibility="gone" />
<com.devstring.imageframe.views.HotspotView
android:id="#+id/hotspot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:visibility="visible" />
</RelativeLayout>
Code:
RelativeLayout.LayoutParams lp = new
RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT);
lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
ImageFrameActivity.hotspotView.setLayoutParams(lp);
ImageFrameActivity.hotspotView.setVisibility(View.VISIBLE);
I have gone through various similar questions but I'm not able to resolve the problem.
try this :
RelativeLayout.LayoutParams lp =
(RelativeLayout.LayoutParams) ImageFrameActivity.hotspotView.getLayoutParams();
lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
ImageFrameActivity.hotspotView.setLayoutParams(lp);
Try using
lp.gravity = Gravity.LEFT;
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>
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
public SomeClass(Context context, SomeType some_arg) {
super(context);
LayoutInflater inflater = (LayoutInflater)context.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.some_layout_with_button, this, true);
m_button=(Button)findViewById(R.id.mButton);
m_textView=(TextView)findViewById(R.id.mTextView);
m_button.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v){
//TODO
}
});
}
In Activity, in onCreate(...) I wrote
this.setContentView(new SomeClass(getApplicationContext(),arg));
SomeClass extends LinearLayout, some_layout_with_button.xml is correct
But on emulator's display - nothing. Why?
UPD:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="20px">
<Button android:id="#+id/mButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BT" />
<TextView android:id="#+id/mTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="16px"
/>
</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RadioGroup android:id="#+id/mRadioGroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton android:id="#+id/mRadioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="60px"
android:text="Text1"/>
<RadioButton android:id="#+id/mRadioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="60px"
android:text="Text2"/>
</RadioGroup>
</LinearLayout>
</LinearLayout>
I think a few calls to http://developer.android.com/reference/android/view/ViewGroup.html#addView(android.view.View,%20int) are missing from your constructor code