My application have a viewpager with the following fragment
1 Login 2 Measure 3 View Data
After the user login and swipe to the measure fragment my app will automatically measure some parameters.
As the viewpager is swipe-able . Is is possible to greyout/disable a fragment in the case where the user want to measure without login.
Thanks.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageButton
android:id="#+id/qt_deleteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/qt_testtype"
android:layout_marginLeft="28dp"
android:layout_marginTop="18dp"
android:layout_toRightOf="#+id/qt_saveButton"
android:background="#drawable/border_button"
android:src="#drawable/delete" />
<ImageButton
android:id="#+id/qt_saveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/qt_deleteButton"
android:layout_toRightOf="#+id/maintxt_measure"
android:background="#drawable/border_button"
android:src="#drawable/save" />
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/main_unknown" />
</FrameLayout>
</RelativeLayout>
I have edit my layout file to the above however the layer below is still clickable. Is there any thing i missed ?
Thanks
Sorry but no, this is how it should probably look like:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- You may change this to your relative layout, just make sure it is fill_parent -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<!-- Everything related to your main activity goes here -->
</LinearLayout>
<LinearLayout
android:id="#+id/faderLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#E0000000"
android:onClick="faderClicked" />
</LinearLayout>
</FrameLayout>
So, in your activity, you will have a function public void faderClicked(View v) where it does nothing at all, and you control the view by changing faderLayout's visibility.
Related
I have this simple activity in my android app but I don't know how to place my button so it appears at the same position on various screen sizes.
I want the button to always be placed at the bottom of the screen. The screenshot shown is from a phone screen. When displayed on a larger screen the button is higher up.
How can I fix this?
Thanks
See this screenshot
You can use RelativeLayout with this parameter (android:layout_alignParentBottom="true")
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Click Me!"/>
</RelativeLayout>
You should use a RelativeLayout
If you have a RelativeLayout that fills the whole screen you should be able to use android:layout_alignParentBottom to move the button to the bottom of the screen.
If your button at the bottom doesn't show then probably the layout above it takes all the space. In this case you can put the button first in your layout file and position the rest of the layout above the views with android:layout_above.
Have a look a RelativeLayout. Use this ViewGroup and add a Button inside it with alignParentBottom
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
<Button
android:id="#+id/button_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alignParentBottom="true"
android:text="HORAIRE"
android:layout_margins="<your_margin_in_dp>" />
</RelativeLayout>
Make footerButton.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="HORAIRE"
android:textColor="#ffffff"
android:textSize="20sp" />
</RelativeLayout>
And add it in all your layout file like below line:
Android Activity_Layout
<RelativeLayout
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" >
<!-- Footer aligned to bottom -->
<include layout="#layout/footer" />
<!-- Content above footer -->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/footer"
android:layout_below="#id/header"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Content goes here"
android:textColor="#FFFFFF"
android:textSize="20sp" />
</RelativeLayout>
</RelativeLayout>
Hope it will solve your problem
This is what I ended up doing. Thanks to everyone who posted, it helped me get in the right direction!
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_main"
tools:context="xxxx.MainActivity"
android:orientation="vertical"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dernières nouvelles Twitter"
android:id="#+id/textView"
android:textStyle="bold"
android:textSize="17dp"
android:paddingLeft="8dp"
android:paddingTop="6dp"
android:paddingRight="6dp"
android:paddingBottom="6dp"
android:layout_alignParentTop="true"/>
<ListView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/listView_tweets"
android:layout_above="#+id/buttonDisplay"
android:choiceMode="none"
android:paddingTop="25dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Horaire"
android:layout_margin="5dp"
android:id="#+id/buttonDisplay"
android:onClick="buttonGotoDisplay"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
I want to open the List view from the bottom of screen to almost little high of middle of screen. I have no idea how to do it. I have just idea about it that it could only be done by fragment and I do not know how to use it in my current activity and xml What I want is shown in following picture :
I hope my question is quite clear. I know How to implement the list view but I do not know ho to implement it in this way I wanted (I mean to appear and disappear with out disturbing other views). this list should overlay other views.
EDIT
including my Xml File so that if you can see what I have done in design
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="content_desc_overlay"
android:src="#drawable/ic_launcher"
android:id="#+id/img_view"
/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/iv_overlay"
android:src="#drawable/doom"
android:scaleType="matrix"
/>
</FrameLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Open List"
android:id="#+id/btn_screenshot"
android:layout_gravity="right|top"
/>
</RelativeLayout>
Any suggestion ? Source code would be appreciated. Thanks
put your list view in a separate blank activity and in the manifest put the theme of activity as dialog
<activity
android:name=".ui.activities.EditSignatureActivity"
android:label="#string/title_activity_edit_signature"
android:theme="#android:style/Theme.Holo.Light.Dialog" >
</activity>
and on click of open list button start new intent:
public void openListButton_OnClick(View v) {
Intent intent = new Intent(HomeActivity.this, List.class);
startActivity(intent);
}
don't forget to resize your new listView activity as much as you want its dimensions and add margins to fit the position you need
I will give you sample. You must need to modify. Ask if any doubts
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="50dp"
android:id="#+id/top_row">
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Text A" />
</LinearLayout>
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Text B" />
</LinearLayout>
</LinearLayout>
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/top_row"
android:layout_marginBottom="15dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="15dp"></ListView>
</RelativeLayout>
Note : You need to load listView with data.
I have the following xml file:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/FrameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</android.support.v4.view.ViewPager>
<LinearLayout
android:id="#+id/musicLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="center"
android:orientation="horizontal"
android:padding="10dp"
android:focusable="true"
android:visibility="visible" >
<ImageView
android:id="#+id/backward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/backward" />
<ImageView
android:id="#+id/stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:src="#drawable/stop" />
<ImageView
android:id="#+id/pausePlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:src="#drawable/play" />
<ImageView
android:id="#+id/forward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingRight="10dp"
android:src="#drawable/forward" />
</LinearLayout>
The framelayout is for an actionbar with tabs which are the viewpager in the above layout. The actionbar works perfect. The problem that I want to solve is that the last linearlayout, which is actually a media player floating in the bottom of the screen, needs to be hidden when I press outside the linearlayout! I have tested the onfocuschangelistener in the musicLayout and onclick in the pageviewer but nothing happens! What am i doing wrong?
Edit:
In case it helps, every tab is a fragment with its own layout which is added to the viewPager.
I think the easiest solution to this problem would be to add a transparent view that matches parent of your ViewGroup. Basically, you would have the ViewPager, LinearLayout and View at the same level. You can then register an onClickListener on your transparent View and that should do the trick.
Layout should be something as simple as this :
<View android:id="#+id/transparent_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"/>
Good day, I have an Activity which contains 4 fragments. The Activity has a footer which I use to switch between these fragment views. Now in one of my fragments, i have some widgets and the last widget is a ListView. The trouble am having is, the last 2 entries in the Listview are not displaying correctly! they are obscured by the footer. I have set my LayoutParameters for both the width and height of the Listview to FILL_PARENT. but its not working. Any idea how i can solve this? Thanks in advance.
My Layout is :
for the fragment:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button android:id="#+id/line_button_id" android:layout_width="160dp"
android:layout_height="wrap_content" android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" android:layout_marginLeft="5dp" android:focusable="true"
android:layout_marginTop="8dp" android:text="#string/line_graph" android:background="#drawable/temp_left_button" />
<Button android:id="#+id/bar_button_id" android:layout_width="160dp"
android:layout_height="wrap_content" android:layout_alignBaseline="#+id/line_button_id"
android:layout_alignBottom="#+id/line_button_id" android:focusable="true"
android:layout_alignParentRight="true" android:layout_marginRight="5dp"
android:text="#string/bar_graph" android:background="#drawable/temp_right_button"></Button>"
<FrameLayout
android:id="#+id/graph_framelayout_id"
android:layout_width="fill_parent"
android:layout_height="280dp"
android:layout_below="#id/line_button_id"
android:padding="4dp"
android:layout_margin="4dp"
android:background="#drawable/rounded_date_filter">
</FrameLayout>
<!-- first cell information, dashboard -->
<LinearLayout
android:id="#+id/row1_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_below="#id/graph_framelayout_id"
android:orientation="horizontal"
android:clickable="true"
android:background="#drawable/rounded_table_row">
<TextView
android:id="#+id/dashboard_datefrom_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:layout_marginLeft="20dp"
android:text="01 may 2012"/>
<ImageView
android:id="#+id/dashboard_image_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/ic_action_search"/>
<TextView
android:id="#+id/dashboard_dateto_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:text="01 sept 2012"/>
</LinearLayout>
<!-- accounts overview listview -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/row1_id"
android:layout_margin="4dp"
android:orientation="vertical"
android:background="#drawable/rounded_date_filter">
<TextView
android:id="#+id/list_text_header_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dp"
android:text="#string/data_grid_text_header_day"
android:background="#drawable/text_header">
</TextView>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView>
</LinearLayout>
</RelativeLayout>
and for the Activity i have this:
<
?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/fragment_container_id"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</FrameLayout>
<include layout="#layout/footer"></include>"
</RelativeLayout>
i replace the fragments with in the framelayout of the Activity
What Layout are you using in your Fragment, this surely won't happen if you use RelativeLayout and set above attribute to your ListView like this :
Try to add this into FrameLayout in your Activity layout.
android:layout_above="#+id/footer"
I have a layout where I need to show a webview on part of the screen. I've set the layout up and in the Graphical Layout in Eclipse, it does look as I want to, like this (logo and heading blacked out):
However when I open this layout in the simulator or on a Phone it shows the WebView as a full screen. How do I make a layout like this? Any help is much appreciated!
Here's my XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/Theme.KB_default"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/header_background_shape" >
<TextView
android:id="#+id/heading"
style="#style/Theme.KB_header"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/app_name" >
</TextView>
<ImageView
android:id="#+id/imageViewPadlock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:contentDescription="#string/global_secure_connection"
android:src="#drawable/padlock" />
</RelativeLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#color/black" >
</View>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.41"
android:orientation="vertical" >
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="40dp"
android:layout_height="20dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="15dp"
android:contentDescription="#string/global_logo"
android:scaleType="fitXY"
android:src="#drawable/logo_transparrent_notext" />
</LinearLayout>
</LinearLayout>
make one of table block as webview
check this link
http://developer.android.com/reference/android/widget/TableLayout.html
You can also check this example by using dialog
http://www.41post.com/4673/programming/android-creating-a-webview-dialog
Well I seem to be the stupidist guy alive. My layout worked but I forgot to add " setContentView(xml.file);" so it never loaded the XML... Stupid