I have been trying everything to get this to work, but to no avail. I tried to use the (AutoResizeTextView) posted here: Auto Scale TextView Text to Fit within Bounds
I created a new class file in my project with the name "AutoResizeTextView" and pasted the above code.
Then i opened the main.xml file and put n the following code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.mn.rl.AutoResizeTextView android:id="#+id/tv"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
in the mainActivity.java file, i have the following code:
package com.mn.rl;
import android.app.Activity;
import android.os.Bundle;
public class rlActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
com.mn.rl.AutoResizeTextView txt = (com.mn.rl.AutoResizeTextView) findViewById(R.id.tv);
txt.setText("Hello");
}
}
I have no errors in the code, and it runs but there is no autoresizing. the text remains the same size. in the xml i have the autoresize textview layout_width and layout_height set to fill parent, yet the font remains small. also tried txt.resize().
What am i doing wrong? Please Help.
there is a slight possibility that that class is only meant for resizing down. not up.
Related
I have got an idea to get rid of some coding when we do initializion of views.
When we create an xml layout in android. At that movement same name class is created with UpperCase Letters with a dialogue with permission. And as i created views with ids. It should create Views and initialize them automatically.
for e.g
close.xml
<?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" >
<Button
android:id="#+id/closeBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/close_img" />
<TextView
android:id="#+id/closeText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Testing Text" />
</LinearLayout>
And automatically generated java code should be.
public class Close extends Activity
{
TextView CloseText;
Button CloseBtn;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CloseText = (TextView)findViewById(R.id.closeText);
CloseBtn = (Button)findViewById(R.id.closeBtn);
}
}
I can read xml and do the other stuff as I explained. But how could i add this module to eclipse and How could i create a service which work in Background all the time in eclipse.
Suggest me how to add this module(Plugin) to eclipse and i am going to use JAXB to generate Java Objects from XML document. Is there any better option.
Here in this website i find that just paste the xml and you will get your java code ready for activity class.
i had attached the link
I have created multiple XML files, but today I reopened my project and I am unable to set the content view to my newly created layout. When I Type "R.layout" and look at the XML files it recommends; I see a list of XML files, but not the one that i want. I have tried cleaning my project and rebuilding everything, but it didn't work. I have also made sure that i'm not importing "Android.R". I am not sure why this is happening. Thanks for your help.
XML Code
<?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>
Tabs Class java
package com.thenewboston.cfil360;
import android.app.Activity;
import android.os.Bundle;
public class Tabs extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs);
}
}
When I want to create a XML file in Android SDK installed ECLIPSE for the purpose of SharedPreferences Activity layout... I do not see that dialog box to appear where I can choose from.
Following are my files.
MainActivity.java
package com.preferences_activity;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
}
});
}
}
Preferences.java
package com.preferences_activity;
import android.os.Bundle;
import android.preference.PreferenceActivity;
public class Preferences extends PreferenceActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
main_activity.xml
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="16dp"
android:text="#string/button1" />
</RelativeLayout>
preferences_activity.xml
<?xml version="1.0" encoding="UTF-8"?>
In the preferences_activity.xml, this is what I get when I create a xml file.
But I wanted to choose a type called preferences while creating a xml file. preferences layout is one of the type of resource available in the dialog box. Others are like: Layout, Values, Menu, AppWidget Provider Searchable, Animation.
If I had a option to choose a preferences layout option while creating a xml file I would be getting the following code:
<?xml version="1.0" encoding="UTF-8"?>
<PreferencesScreen
xmlns:android="http://schemas.android.com/apk/res/android">
</PreferenceScreen>
My Question is again: Where can I get that dialog box from while creating xml file where I can choose the resource type?
I am sorry if this question sounds funny. But I am struggling with it for few days in a row.
Thank you all.
For future Visitors:
I was struggling because I was using eclipse app instead of the one that was under adt-bundle. If you use the app under the adt-bundle, that has a logo with {} and light green background than you will have an options to choose a layout or any sorts of resources while creating an xml file. Pls, one more thing to note, I was having hard time to find a wizard for creating a xml file ( I could do it manually with right clicking the project and other and choosing xml file).. but I m talking about the wizard on the menu bar, you should be able to see it if you use this app under adt-bundle instead of regular eclipse. My answer may not be that likable, but sharing for future android beginners.
Ex: I have a project with UI contains a button..
Activity:
package android.tuanshaker.myproject.com;
import android.app.Activity;
import android.os.Bundle;
public class MyProjectActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
And file main.xml:
<?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" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
</LinearLayout>
I want to display code and xml of my project by textview..How do i can to get them?
Copy the xml, js code files to res/raw. Use Context.getResources().openRawResource() to read them.
In addition, you can use jHighlight to format those source codes (in a web view).
So I just started playing around with android and I'm trying to see what things I can do. I was following the very first android tutorial: http://developer.android.com/training/basics/firstapp/index.html and at the very end, you programmatically define a TextView. I wanted to change this to be defined in a new layout, so I wrote this (it is named display_message.xml):
<?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" >
<TextView android:id="#+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
And in the DisplayMessage class, I changed it to this:
public class DisplayMessage extends Activity {
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.display_message);
// Get message from intent
Intent intent = getIntent();
String message = intent.getStringExtra(FirstActivity.EXTRA_MESSAGE);
// Get the text view
TextView textView = (TextView) findViewById(R.id.text_view);
textView.setText(message);
}
}
However, Eclipse says that it doesn't know what R.layout.display_message is, nor does it know what R.id.text_view is. Is there somewhere else I need to define them or something? Where did I mess up?
It seems correct but be sure that the R class imported is the correct one.
Sometimes Eclipse imports android.R but the R file you need to import is your.package.name.R