I have 2 files in the res.
Activity_main.xml is
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.test2.MainActivity"
tools:ignore="MergeRootFrame" />
fragment_main.xml is
<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="com.example.test2.MainActivity$PlaceholderFragment" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</RelativeLayout>
I plan to change the layout where I problem in this current layout when I drag and drop all item just overlap on each other how to make a nice form type layout? What adjustment and which file must I adjust?
It sounds like you are using the Eclipse GUI tools to create your layout. I strongly suggest that you read about Android Layouts. If you want, you can edit the XML layout text directly or at the very least this will help you understand the properties you can set for your controls to get the exact look that you want.
Related
I'm trying to debug a view that I'm creating programmatically. I'd like to be able to see what the exact XML is of the view after it's created.
Really I'd like to be be able to do something like Log.d(TAG,view.toString())
And get an output like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="#+id/activity_main"
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="sampleapp.example.com.tr221test.MainActivity">
<Button android:id="#+id/surveyButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Take Survey!"/>
</RelativeLayout>
Is there anyway I can programmatically see what the xml is of a view?
There is nothing built in for that. You would have to write your own View-hierarchy-to-XML code or see if somebody has a library for that.
Or, use Android Studio's layout inspector.
Or, use uiautomatorviewer.
Or, use Stetho.
I have a very simple listview, but now it shoes all empty when open it, I wanna user see the light grey lines in this empty list view to let them know this is something will list, Is there any way to show the lines when the listview still empty please?
<?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:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
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="com.anna.DiscoverActivity">
<android.support.v7.widget.SearchView
android:id="#+id/searchview"
app:queryHint="Search HoodMark"
android:background="#color/colorAccent"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<ListView
android:layout_below="#id/searchview"
android:id="#+id/discover_list"
android:divider="#color/colorAccent"
android:dividerHeight="4px"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</RelativeLayout>`
Yes there is. Create an emptyView, design it as you like then supply it to the your adapter. Like this:
//inflate your empty view
View emptyView=getLayoutInflater().inflate(R.layout.emptyViewLayout,null,false);
//set to your listView
listView.setEmptyView(emptyView);
I'm thinking of making an app's first view like this: it's just a basic search view with one EditText and two Button on it. I want the background image zooming in and out when user stay on this view, typing or doing nothing.
So I add zoomin.xml and set the animation to the view. Zooming is working but only problem is that it's zooming everything. I know it's because I set background image in the root element of the xml, but I don't know how to make it ONLY zoom in the background picture without affecting other views.
Here's my background image code in root element.
<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="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:background="#drawable/bcg2"
android:orientation="vertical"
android:gravity="center">
So I'm thinking if any floating view will do this? But I don't know how to do it. Or any other suggestion?
Thanks!
Use a fullscrean ImageView instead of the background attribute of the Linearlayout and zoom only the image
<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">
<ImageView
android:id="#+id/image_to_zoom"
android:src="#drawable/bcg2"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:orientation="vertical"
android:gravity="center"/>
</RelativeLayout>
I tried to add a background image to an Android app using android:background="#drawable/imageURL". I added the image to the drawable-hdpi folder, but I'm getting an error. I'm trying to add the image to a RelativeLayout. I also tried to use LinearLayout but it didn't work either.
So how to add background image to my app within RelativeLayout in Android?
What is the error?
<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:background="#drawable/abc.png"
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" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</RelativeLayout>
replace
android:background="#drawable/abc.png"
with
android:background="#drawable/abc"
From the documentation:
May be a reference to another resource, in the form
"#[+][package:]type:name"
as you can see the extension is not part of the value of the attribute
just write #drawable/abc instead of #drawable/abc.png
Looking for ways to customize my spinner, I heard about http://android-holo-colors.com so I went there and generated a spinner. When I download the zip, it only contains a res file that has no layout folder. How would I use the generated spinner in a simple bare bone android app? As in I imagine I have to link the generated files to a spinner that I create in a layout file. How would I do that? Say my spinner in the layout is
<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: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" >
<Spinner
android:id="#+id/my_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
How do I wire it up with the generated res stuff?
The tool generates a custom pair of theme and styles XML. You should use the theme for your activity/application, or even use only the styles you need.
EDIT: added an example as requested
Given you chose "MyApp" during generation, the zip will contain (besides the drawables and a theme definition) a set of styles (res/values/myapp_styles.xml and res/values-v11/myapp_styles.xml).
In order to use such resources within your layout you have to:
merge the generated res/ folder into your project res/ folder
use the given styles in your layouts accordingly.
eg:
<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: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" >
<Spinner
android:id="#+id/my_spinner"
style="#style/SpinnerAppTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
where #style/SpinnerAppTheme refers to the spinner-specific style defined in res/values/myapp_styles.xml (and res/values-v11/myapp_styles.xml for API>=11).