I have layout file custom_lock.xml. It has 3 child layouts. Problem is when I try to access the elements of the layout from MainActivity.java, it returns null. Its driving me nuts. Please help me. Thanks.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:name="#+id/place1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:gravity="center"
android:text="Place"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:name="#+id/listofapps"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#android:color/holo_blue_light"
android:text="List of Apps" />
<ListView
android:name="#+id/sites"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#android:color/holo_green_light" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:name="#+id/calories"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#android:color/holo_purple"
android:text="Health Data" />
<ListView
android:name="#+id/dialer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#android:color/darker_gray" />
</LinearLayout>
</LinearLayout>
Following is my MainActivity.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_lock);
startService(new Intent(this, MyService.class));
TextView placexml = (TextView) findViewById(R.id.place1);
if (placexml == null)
System.out.println("placexml");
String place = "work";
//System.out.println("place: "+place);
placexml.setText(place);
boolean isApiRunning = ContextSdk
.isSemusiSensing(getApplicationContext());
if (isApiRunning)
Api.stopContext();
else {
SdkConfig config = new SdkConfig();
config.setPlacesAccuracyLevel(PlacesAccuracyLevel.EAccuracyHigh);
config.setActivityAccuracyLevel(ActivityAccuracyLevel.EAccuracyHigh);
config.setActivityTrackingAllowedState(true);
config.setAnalyticsTrackingAllowedState(true);
config.setDemographicsTrackingAllowedState(true);
config.setPedometerTrackingStateAllowed(true);
config.setPlacesTrackingAllowedState(true);
config.setRuleEngineEventStateAllowed(true);
Api.startContext(getApplicationContext(), config);
}
// reloadRssHandler.postDelayed(relaodRssRunnable, time);
//updateUILayer();
/*
txt1.setOnClickListener(new OnClickListener() {
#Override public void onClick(View arg0) { // TODO Auto-generated
method stub System.out.println("finishing......."); finish();
}
});
*/
}
When I run this program, "placexml" gets printed on console. I don't know, why this is happening. place1 is returning null from xml. Please help.
Change lines
android:name="#+id/place1"
to
android:id="#+id/place1"
You need to set ID instead of name.
setContentView(R.layout.custom_lock);
Wrong name of your layout "custom_layout"?
Try changing
<TextView
android:name="#+id/place1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:gravity="center"
android:text="Place"
android:textColor="#000000" />
with
<TextView
android:id="#+id/place1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:gravity="center"
android:text="Place"
android:textColor="#000000" />
Related
I have two ViewPager on the same view with weight= 70/30 . The problem is when the keyboard pops, my both view keep the same weight and do not display my EditText.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
tools:context="com.suez.memboard.fragments.formWaterQuality">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="30">
<com.suez.memboard.controls.TextView
android:id="#+id/path"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:textAppearance="#style/FreeTextBold" />
<LinearLayout
android:id="#+id/date_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<com.suez.memboard.controls.TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="forms.label.intervention_date"
android:textAppearance="#style/FreeText"
android:textSize="15sp" />
<com.suez.memboard.controls.TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" : "
android:textAppearance="#style/FreeText"
android:textSize="15sp" />
<com.suez.memboard.controls.DateTimeText
android:id="#+id/date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:drawableRight="#drawable/ic_date_range_black_24dp"
android:focusable="false"
android:hint="forms.label.intervention_date"
fab:type="date" />
</LinearLayout>
<Spinner
android:id="#+id/spin_location"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TabLayout
android:id="#+id/tabA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#color/suez_blue_1"
app:tabGravity="fill" />
<ImageButton
android:id="#+id/buttonAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/suez_blue_1"
android:src="#drawable/ic_add_box_white_48dp" />
</LinearLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewA"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="70">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TabLayout
android:id="#+id/tabB"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/suez_blue_1"
app:tabGravity="fill" />
</LinearLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewB"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<FAB ....>
I think my last solution is to make disappear my picker at the top when my keyboard pops. How can I do this?
Hope this help you :
public class YourActivity extends BaseActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_activity);
attachKeyboardListeners();
}
#Override
protected void onShowKeyboard(int keyboardHeight) {
// when keyboard is shown
yourWidget.setVisibility(View.GONE);
}
#Override
protected void onHideKeyboard() {
// when keyboard is hidden
yourWidget.setVisibility(View.VISIBLE);
}
}
Try to use ScrollView in parent view, for example-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true">
<ScrollView
android:id="#+id/scroll_view_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:fillViewport="true"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
..................................
type your code here
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorWhite"
android:orientation="vertical">
..................................
type your code here
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
You can set listeners when keyboard is opened and closed.
// ContentView is the root view of the layout of this activity/fragment
contentView.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
Rect r = new Rect();
contentView.getWindowVisibleDisplayFrame(r);
int screenHeight = contentView.getRootView().getHeight();
// r.bottom is the position above soft keypad or device button.
// if keypad is shown, the r.bottom is smaller than that before.
int keypadHeight = screenHeight - r.bottom;
Log.d(TAG, "keypadHeight = " + keypadHeight);
if (keypadHeight > screenHeight * 0.15) { // 0.15 ratio is perhaps enough to determine keypad height.
// keyboard is opened
} else {
// keyboard is closed
}
}
});
I have one relativeLayout and three view's inside RelativeLayout. There views are place on each other.
<RelativeLayout
android:id="#+id/includelayoutgroup"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/transparentColorView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:clickable="true"
android:visibility="visible" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/keyboard_main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible">
<include
layout="#layout/transfer_keyboard_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/finalRequestView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:clickable="true"
android:visibility="visible">
<include
layout="#layout/fragment_transfer_new_version_container_child"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</RelativeLayout>
Is it a possible to reverse position my view's? I mean,in my code last Layout is finalRequestView and in button click i would to my last view in first position,and other view's place on my view,
How i can solve this problem?
I try to reverse layout by following demo & it works as you want, please take a look
ReverseLayout.java
public class ReverseLayout extends AppCompatActivity {
LinearLayout llRoot;
Button btReverseLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reverse_layout);
llRoot = (LinearLayout) findViewById(R.id.llRoot);
btReverseLayout = (Button) findViewById(R.id.btReverseLayout);
btReverseLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ArrayList<View> alViews = new ArrayList<View>();
for (int i = llRoot.getChildCount() - 1; i >= 0; i--) {
View view = llRoot.getChildAt(i);
llRoot.removeViewAt(i);
alViews.add(view);
}
for (int j = 0; j < alViews.size(); j++) {
llRoot.addView(alViews.get(j));
}
}
});
}
}
reverse_layout.xml layout file
<?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/activity_6"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.tosc185.testproject.Activity6">
<LinearLayout
android:id="#+id/llRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF0000"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00FF00"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#0000FF"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:textSize="16dp" />
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/btReverseLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Reverse Layout" />
</RelativeLayout>
my app contains "Settings" activity which contains 2 imagebuttons "back" and "about", whenever i press any of these buttons i get:
"couldnt save which view has focus because the focused view android.widget.LinearLayout#4055a9e0 has no id"
the xml code for my_settings:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/ll2"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="15" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_margin="8dp"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/settings" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|end"
android:orientation="horizontal" >
<ToggleButton
android:id="#+id/tb1"
android:layout_margin="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="#string/sett1" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/border2"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/ll_set_back"
android:layout_margin="3dp"
android:gravity="center"
android:layout_weight="1"
android:orientation="vertical" >
**<ImageButton
android:id="#+id/st_ibt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/action_btn"
android:src="#drawable/back_ic" />**
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/back"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/ll_set_about"
android:layout_margin="3dp"
android:gravity="center"
android:layout_weight="1"
android:orientation="vertical" >
**<ImageButton
android:id="#+id/st_ibt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/action_btn"
android:src="#drawable/about_ic" />**
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/about"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
dont pay attention to the "scrollview" (i dont think the problem is there), just look at the end of the code for the 2 imagebuttons..
and this the java code for Settings:
public class Settings extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.my_settings);
//code...
ImageButton goBack=(ImageButton)findViewById(R.id.st_ibt1);
ImageButton about=(ImageButton)findViewById(R.id.st_ibt2);
goBack.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent intent=new Intent(Settings.this, MainActivity.class);
startActivity(intent);
//finish();
}
});
about.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent intent=new Intent(Settings.this, About.class);
startActivity(intent);
//finish();
}
});
}
so, how to fix this? i dont understand what this error means.. any suggestions
I think the problem is :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:orientation="vertical" >
You enable focus to this LinearLayout, but you didn't provide any id for it.
I have a layout and every time my button is pressed I want to add a group of views stored in another layout. This is the way I tried it so far. The error in logcat is:
"E/AndroidRuntime(7900): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first."
Code:
material_cost.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/materialCostText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Κόστος Υλικών"
android:textColor="#FF0000"
android:textSize="16sp"
android:textStyle="bold"
android:gravity="center_horizontal"
android:layout_margin="5dp"/>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="4dp"
android:background="#33B5E5" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/materialWrapper">
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<Button
android:id="#+id/btnMaterialSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Αποθήκευση"
android:layout_weight="50"/>
<Button
android:id="#+id/btnMaterialAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Προσθήκη πεδίου"
android:layout_weight="50"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
material_cost_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/materialItem"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="50dp"
android:layout_height="wrap_content"
android:id="#+id/materialText"
android:text="Υλικό"
android:textSize="16sp"
android:textStyle="italic"
android:layout_weight="50"
android:layout_marginLeft="5dp"/>
<EditText
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="50"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="50dp"
android:layout_height="wrap_content"
android:id="#+id/materialText"
android:text="Τιμή μονάδας"
android:textSize="16sp"
android:textStyle="italic"
android:layout_weight="50"
android:layout_marginLeft="5dp"/>
<EditText
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="50"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="50dp"
android:layout_height="wrap_content"
android:id="#+id/materialText"
android:text="Ποσότητα"
android:textSize="16sp"
android:textStyle="italic"
android:layout_weight="50"
android:layout_marginLeft="5dp"/>
<EditText
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="50"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="4dp"
android:background="#33B5D8" />
</LinearLayout>
</LinearLayout>
And finally my class:
public class MaterialActivity extends Activity implements OnClickListener {
Button btnAdd;
LinearLayout rootLayout;
View layoutItem;
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.material_cost);
btnAdd = (Button) findViewById(R.id.btnMaterialAdd);
rootLayout = (LinearLayout) findViewById(R.id.materialWrapper);
layoutItem = getLayoutInflater().inflate(R.layout.material_cost_item, rootLayout,false);
rootLayout.addView(layoutItem);
btnAdd.setOnClickListener(this);
}
public void onClick(View v){
switch (v.getId()){
case R.id.btnMaterialAdd:{
inflateEntry();
break;
}
}
}
private void inflateEntry() {
// TODO Auto-generated method stub
Log.v("debug","pressed");
rootLayout.addView(layoutItem);
}
}
you need to inflate the view again every time you click the button:
private void inflateEntry()
{
// TODO Auto-generated method stub
Log.v("debug","pressed");
View layoutItem = getLayoutInflater().inflate(R.layout.material_cost_item, null);
rootLayout.addView(layoutItem);
}
I am currently working on a application .when i installed my_app in android mobile while rotating in horizontal view my buttons are missing,please help!! Thanks in advance
My java coding is:
public class Draw extends Activity {
ImageView iv1;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final DrawView drawView = new DrawView(this);
setContentView(R.layout.draw);
FrameLayout frm_layout=(FrameLayout) findViewById(R.id.main_frame);
iv1=(ImageView) findViewById(R.id.imageView1);
frm_layout.addView(drawView);
Intent myIntent = getIntent(); // this is just for example purpose
String test=myIntent.getExtras().getString("guided");
if(test.equals("1"))
{
iv1.setImageResource(R.drawable.untitled);
iv1.setAlpha(100);
}
else
{
//iv1.setImageResource(null);
}
//Toast.makeText(getApplicationContext(), test.toString(), 2000).show();
Button btn_undo=(Button) findViewById(R.id.button1);
btn_undo.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
drawView.onClickUndo();
}
});
Button btn_redo=(Button) findViewById(R.id.button2);
btn_redo.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
drawView.onClickRedo();
}
});
}
}
My XML coding is below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#android:color/white" >
<FrameLayout
android:id="#+id/main_frame"
android:layout_width="fill_parent"
android:layout_height="472dp"
android:background="#android:color/white" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</FrameLayout>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Redo" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Undo" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Save" />
</RelativeLayout>
</LinearLayout>
Just Copy and Past in you xml file, it wil run completely. I have tested.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#android:color/white" >
<FrameLayout
android:id="#+id/main_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white" android:layout_weight="0.1">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</FrameLayout>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.9" android:layout_gravity="bottom" android:layout_marginTop="-10dp">
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Redo" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Undo" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Save" />
</RelativeLayout>
</LinearLayout>
Hope this is what you want.
do one thing make a folder named Layout-land in res folder , in which put your xml file. now you can design your xml in horizontal mode . do whatever changes you want in that file and check :
otw put a scroll bar in whole layout and then check :) good luck