I am making an app, and I have the following XML file:
<?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="#f4f4f4" >
<ExpandableListView
android:id="#+id/lvExp"
android:layout_width="match_parent"
android:layout_height="325dp" />
<Button
android:id="#+id/add_claim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Claim" />
</LinearLayout>
I made a button called View_list that wants to see only the expandable list view on the entire page. what I did is create a new XML file, and added the follwing include statement:
<include android:id="#+id/lvExp"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
However, I realized that this will now work for two reasons
1 - There is no layout ID
2- I only want the list, not the button and everything else I am going to put in the original layout. What is going to happen is if I add something to the list, I need to be able to view it without the option of adding antthing to it.
My question is therefore this:
How do I find the layout ID and how can I prevent the entire layout from showing, and only show the list. I would really appreciate some advice.
The include should say:
<include layout="#layout/View_list"
android:id="#+id/lvExp"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
This includes the View_list.xml layout in another layout.
But I dont really understand why you would use an include here if you don't want to re-use the whole layout, but only the list part of it. includes exist to easily use layouts in other layouts, if you need just a ListView, use just a ListView.
EDIT: I'm not sure anymore if I got your question right, but I'll not delete the answer because you commented on it.
If you want to hide the button or other Views on the click of a button, you can set their visibility to gone programmatically.
Related
I have been trying for a long time to make Cards similar to appearance that of Google Play Store, ie cards of Different sizes , with images and all inside the card. Any tips on how to proceed.
Basically you just create a layout (RelativeLayout, LinearLayout, etc) as a child of your cardview element and make it look however you want.
For example...
<android.support.v7.widget.CardView
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="200dp"
card_view:cardElevation="2dp"
card_view:cardBackgroundColor="#android:color/white"
card_view:cardCornerRadius="2dp">
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent">
//Your desired layout here
</RelativeLayout>
</android.support.v7.widget.CardView>
You can take a look at the MaterialList implementations for some good examples.
I am creating an Android Application having two layouts. All layouts have some common features like the top part is same and the only difference is at the bottom part.
Currently I have created two separate java files for two layouts. And I have simply copied the code which implements similar functionality like buttons etc
The part seen is the pic is the top part of the layout which is same in both the layouts;
Is there any way with which I can optimize the functionality by having reusable code
In my opinion this is helpful using <include> in your main layout.
STEP:
you have to create one XML file for your common layout.
topbar.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width=”match_parent”
android:layout_height="wrap_content"
android:background="#color/titlebar_bg">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/gafricalogo" />
</FrameLayout>
like this way now you have to include this XML file to where you have to require.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">
<include layout="#layout/topbar"/>
...
</LinearLayout>
I think this tab bar can also be used for this..
below is the link for complete tutorial...
http://mindstick.com/Articles/7e659092-3046-4461-97ba-b2b28616241e/?tab%20layout%20android%20application
I had researched many sources and tried but still cannot move the position of handle from center to right.
<SlidingDrawer
content >
<ImageButton <-- this is handle
android:id="#+id/handle" <-- i want to customize position
android:layout_width="50px"
android:layout_height="60px"
android:background="#drawable/icon_other" />
<LinearLayout
android:id="#+id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/background_others"
android:orientation="vertical" >
//content
</LinearLayout>
</SlidingDrawer>
So what to do to customize the position?
Please give opinion. Thanks
Use a TableLayout. This works similar to a HTML Table concept, allowing you to define rows and columns where to place buttons and other components.
If you don't want to use a table layout for the entire screen, you should be able to nest the layout within another....
Just as the title says...I want to include a MapView inside of another activity. For instance, I want the MapView to take up half of the screen, and below that, include some other widgets - text fields, buttons, whatever. I have been tinkering with it, but so far I have been unsuccessful - the map does take up only half the screen, but no widgets show up.
Any clues? Is this possible, or is the Google Map integration strictly using the map as a full screen?
Please post your xml layout!
You are just doing it wrong. :-D
A mapview will work like any other widget. I strongly believe there is a mistake in your layout.
This one will work for instance!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/h1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<CheckBox
android:text="Satellite"
android:id="#+id/satellite"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</CheckBox>
<ImageView
android:id="#+id/image"
android:layout_width="75dip"
android:layout_height="75dip"
android:layout_marginRight="6dip"
android:src="#drawable/uoicon" />
</LinearLayout>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="0zDdYFYf6Ir2W-NuiHPLAoFjsq0nmqRhPfzjY3A"/>
</LinearLayout>
Just a guess but you're using a LinearLayout to contain the MapView and other widgets but you forgot to set the orientation to vertical? The default for LinearLayout is horizontal.
It came to mind because it's something I've done 2 or 3 times myself. Totally confusing as effectively the other widgets 'disappear' off the right-hand side of the screen. It eventually got engrained in my mind and I always make sure to explicitly specify orientation now when I use LinearLayout.
I have met a very strange issue in android FrameLayout.
I am trying a very simple game which has a SurfaceView, and when the game ends, I want to popup another view on top probably displaying some text. This is very similar to android sample lunarlander code. However I can't get it work. Here is the strange issue:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/game_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.tmh.FunMatch.MainGamePanel
android:id="#+id/game_panel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.tmh.FunMatch.MyText
android:id="#+id/text"
android:text="test"
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center_horizontal"
android:textColor="#88ffffff"
android:textSize="24sp"/>
</RelativeLayout>
For above FrameLayout, I want to show the second TextView when game finished. However it won't show after I call TextView.setVisibility(VISIBLE).
I did a lot experiment, if I initially set the TextView as VISIBLE, then at some point set it to INVISIBLE in the code. (My understanding is the TextView must be initially showed on the screen once then I turned it into INVISIBLE). If I did so, when the game finished, the TextView will be correctly shown.
I highly doubt it's an android bug. I changed android LunarLander code, I don't know why LunarLander did work and show the Text on the screen.
If anyone had run into the same issue, please tell me what's wrong with my code or is there a hidden bug?
Thanks