I am creating my layout entirely in XML. I wish to show a ListView and always have a button at the bottom of the screen like in the default FullScreenActivity. However, the issue is that the button that is at the bottom is also appearing at the top of the screen.
<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="#ff000000"
tools:context=".ChannelNameActivity">
<ListView
android:id="#+id/channelListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/black_overlay"
android:orientation="horizontal"
tools:ignore="UselessParent">
<Button
android:id="#+id/dummy_button"
style="?metaButtonBarButtonStyle"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="#string/dummy_button" />
</LinearLayout>
</RelativeLayout>
(Code note from OP's previous question: ArrayAdapter unable to update contents)
Because in your onCreate() you are adding Activity Layout as Header View to your ListView which is unnecessary (not required).
So Just remove below code lines from onCreate()
final View contentView = (View)getLayoutInflater().inflate(R.layout.activity_channelname, null);
channelListView.addHeaderView(contentView);
Here you have to use android:layout_above="#+id/lnlLayout" attribute in ListView and android:alignParentBottom="true" on LinearLayout
<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="#ff000000"
tools:context=".ChannelNameActivity">
<ListView
android:id="#+id/channelListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/lnlLayout"
android:keepScreenOn="true"/>
<LinearLayout
android:id="#+id/lnlLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/black_overlay"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
tools:ignore="UselessParent">
<Button
android:id="#+id/dummy_button"
style="?metaButtonBarButtonStyle"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="#string/dummy_button" />
</LinearLayout>
</RelativeLayout>
Related
I have layount who include one layout, duplicate two time ("include"):
<?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:background="#color/colorButtonNiebieski">
<!-- LAYOUT GRACZ (A) -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1.0"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.45"
android:scaleY="-1"
android:scaleX="-1"
android:paddingBottom="10dp">
<include
android:id="#+id/lay1"
layout="#layout/layout_pojedynek_duplikat" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.05"
android:gravity="center"
android:scaleY="-1"
android:scaleX="-1">
<TextView
android:id="#+id/txt_gracz_A_liczba_punktow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:textSize="30dp"
android:textColor="#color/colorWhite"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.05"
android:gravity="center">
<TextView
android:id="#+id/txt_gracz_B_liczba_punktow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7"
android:textSize="30dp"
android:textColor="#color/colorWhite"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.45"
android:paddingBottom="10dp">
<include
android:id="#+id/lay2"
layout="#layout/layout_pojedynek_duplikat" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
layout_pojedynek_duplikat.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1.0">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:weightSum="1.0"
android:background="#00ff0000"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.3"
android:gravity="center">
<TextView
android:id="#+id/txt_gracz_A_i_B_nazwa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="POLSKA"
android:textSize="40dp"
android:textColor="#color/colorWhite"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.7"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1.0">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1.0"
android:layout_weight="0.5"
android:orientation="horizontal">
<ImageView
android:id="#+id/img_pojedynek_wariant_A"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:src="#drawable/argentyna"
android:padding="5dp"
android:adjustViewBounds="true"/>
<ImageView
android:id="#+id/img_pojedynek_wariant_B"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:src="#drawable/kambodza"
android:padding="5dp"
android:adjustViewBounds="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1.0"
android:layout_weight="0.5"
android:orientation="horizontal">
<ImageView
android:id="#+id/img_pojedynek_wariant_C"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:src="#drawable/watykan"
android:padding="5dp"
android:adjustViewBounds="true"/>
<ImageView
android:id="#+id/img_pojedynek_wariant_D"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:src="#drawable/polska"
android:padding="5dp"
android:adjustViewBounds="true"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
In java file I try set font for txt_gracz_A_i_B_nazwa text field:
TextView txt_gracz_A_i_B_nazwa = (TextView) findViewById(R.id.txt_gracz_A_i_B_nazwa);
txt_gracz_A_i_B_nazwa.setTypeface(myFontBold);
But this set font for only one view:
How can I fix this problem?
DO that for every view. Or create a new View class that's a child of TextView and sets the font, and use that instead of TextView.
Yes, Android's font handling sucks.
When you call Activity.findViewById(), the system will traverse your view hierarchy starting from the root until it finds a view with the given id. In other words, Activity.findViewById() will return the first view with that id in your layout. It will not return all views with that id.
For this reason, it is generally advised to not re-use ids within a single layout. However, this advice is often not practical, and you shouldn't feel bad about your current layout. But it does mean that you will need to call TextView.setTypeface() twice, and that you will need some way to access the second view with the id txt_gracz_A_i_B_nazwa.
You can do this by limiting the scope you search with findViewById(). Instead of using Activity.findViewById(), instead use View.findViewById(). So you could write something like this:
View lay1 = findViewById(R.id.lay1);
TextView txt1 = (TextView) lay1.findViewById(R.id.txt_gracz_A_i_B_nazwa);
txt1.setTypeface(myFontBold);
View lay2 = findViewById(R.id.lay2);
TextView txt2 = (TextView) lay2.findViewById(R.id.txt_gracz_A_i_B_nazwa);
txt2.setTypeface(myFontBold);
Looks like a small logic flaw. The problem with reusing the same layout two times, is that you have the identical IDs although they represent two entirely different UI elements.
lay1.findViewById(your_text_field_id).setFontType
lay2.findViewById(your_text_field_id).setFontType
Should fix you. You can't use generic findViewById as it will grab the first one and use it. Hope that helps.
In my app I have several fragments with different ListViews, but for all them I want to use the same empty view, so I created a separate layout with the empty view and added it to the other layouts using
<include
android:id="#+id/empty"
layout="#layout/empty_view"/>
Everything works as expected but now I'm trying to make that view clickable so I can reload ListView when the user taps on the empty view, however I can't make it work. Any idea on how to do it?
This is what I have tried so far:
(empty_view.xml)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:gravity="center">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="center"
android:src="#drawable/error_icon"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#929292"
android:textSize="24sp"
android:text="#string/empty_list_error"/>
</LinearLayout>
fragment_list.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true">
<Spinner
android:id="#+id/spinner_filter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/activity_vertical_margin"
android:layout_marginLeft="#dimen/activity_vertical_margin"
android:layout_gravity="center_horizontal"
android:visibility="gone"/>
<include
android:id="#+id/empty"
layout="#layout/empty_view"/>
<ProgressBar
android:id="#+id/loading_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:indeterminate="true"
style="#android:style/Widget.Holo.ProgressBar.Large"/>
<LinearLayout
android:id="#+id/list_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/primary_color"
android:padding="#dimen/activity_vertical_margin"
android:layout_below="#id/spinner_filter"
android:visibility="gone">
<TextView
android:layout_width="0dp"
android:layout_weight="5"
android:layout_height="wrap_content"
android:textColor="#color/white_90pct"
android:textAllCaps="true"
android:text="#string/subject_indicator"/>
<View
android:layout_width="1dp"
android:layout_height="15dp"
android:layout_gravity="center_vertical"
android:background="#color/light_color"/>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:singleLine="true"
android:gravity="end"
android:textColor="#color/white_90pct"
android:textAllCaps="true"
android:text="#string/grade_indicator"/>
</LinearLayout>
<ListView
android:id="#+id/semesters_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/list_header"/>
</RelativeLayout>
Java class (onCreateView)
LinearLayout emptyView = (LinearLayout) view.findViewById(R.id.empty);
emptyView.setOnClickListener(this);
I also tried adding the next attributes to the xml but still not working:
android:focusableInTouchMode="true"
android:focusable="true"
android:descendantFocusability="blocksDescendants"
Since you have already specified the linearlayout to be clickable, you just need to specify the method for the onClick event.
So add you your linearLayouts xml, the onClick attribute as below: (focusable may be needed too)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:onClick="layoutClicked"
android:focusable="true"
android:gravity="center">
Then in your code have the method to go with it
public void layoutClicked(View v)
{
// Your code here
}
Try emptyView.setOnTouchListener()
Are you including empty_view into another view that blocks descendant focusability?
Since your edit
Your ListView is on top of the empty_view and blocking clickability.
Since your empty view fills its parent, make sure your include tag for your empty view is the last in the other layout so it will be top-most in the z-order.
I'm trying to implement a landscape layout for my Android project. I had it semi working previously, other than that "leftRightLinear" was being overlapped slightly by the button layout at the bottom.
Since trying to fix that problem, I've given up and rolled back to my working version, which is no longer working and I can't figure out why.
The contents of pendingLinear and semesterLinear aren't displaying.
Any ideas?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/mainLinear"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/leftRightLinear"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true" >
<LinearLayout
android:id="#+id/leftLinear"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="fill_parent" >
<TextView
android:text="#string/pendingUnits"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ScrollView
android:id="#+id/pendingScroll"
android:layout_width="fill_parent"
android:layout_marginBottom="0dp"
android:layout_height="0dp"
android:background="#drawable/border">
<LinearLayout
android:id="#+id/pendingLinear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:id="#+id/rightLinear"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="fill_parent" >
<TextView
android:text="#string/semesters"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ScrollView
android:id="#+id/semesterScroll"
android:layout_width="fill_parent"
android:layout_marginBottom="0dp"
android:layout_height="0dp"
android:background="#drawable/border">
<LinearLayout
android:id="#+id/semesterLinear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/border_confirm"
android:layout_alignParentBottom="true" >
<Button
android:id="#+id/saveButtonSemester"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:onClick="clickSave"
android:text="#string/button_save"
/>
<Button
android:id="#+id/confirmBtn"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="#string/confirm"
android:onClick="clickConfirm"
/>
</LinearLayout>
The contents of pendingLinear and semesterLinear aren't displaying
It's because both of your ScrollView are set android:layout_height="0dp". Change them to android:layout_height="fill_content", like so:
<ScrollView
android:id="#+id/pendingScroll"
android:layout_width="fill_parent"
android:layout_marginBottom="0dp"
android:layout_height="fill_parent">
About this problem
"leftRightLinear" was being overlapped slightly by the button layout at the bottom
To let leftRightLinear sit above the button layout, first give the button layout a name
<LinearLayout
android:id="#+id/buttonLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true" >
Then add this attribute to leftRightLinear, android:layout_above="#+id/buttonLayout", like so:
<LinearLayout
android:id="#+id/leftRightLinear"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/buttonLayout"
android:layout_alignParentTop="true" >
Here's the result: (Background of the left scrollview is set black)
pendingLinear and semesterLinear do not have any contents so there is nothing to be shown, they are there - they exist - they are just empty.
Are you adding contents to them dynamically ? if so I'd like to look at the code otherwise try inserting a TextView inside one of them (or both) to confirm that they are being shown.
My app have an activity with layuot like this
<RelativeLayout
android:id="#+id/layoutMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/backgroundchatfixed">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/layoutKhungChat"
android:id="#+id/svChat">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/layoutChat">
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/background_khungchat"
android:layout_alignParentBottom="true"
android:id="#+id/layoutKhungChat">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/khungchat_chat"
android:layout_centerVertical="true"
android:id="#+id/etChatbox"/>
</RelativeLayout>
</RelativeLayout>
When i touch my Edittext, only layout "layoutKungChat" push up.
Any solution to push up also Scrollview above it?
Thanks.
Try adding this to the activity tag in the manifest:
android:windowSoftInputMode="adjustPan"
use this code
<RelativeLayout
android:id="#+id/layoutMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/backgroundchatfixed">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/background_khungchat"
android:layout_alignParentBottom="true"
android:id="#+id/layoutKhungChat">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/khungchat_chat"
android:layout_centerVertical="true"
android:id="#+id/etChatbox"/>
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/layoutKhungChat"
android:id="#+id/svChat">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/layoutChat">
</LinearLayout>
</ScrollView>
the one in the last always be written over the other layouts so if you want like buttons to be above an image layout as an example write it inside of layout below the image
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"