I have a xml file which contains TextView and Leanback VerticalGridView. Left/right/down focus is working fine, but then I can't refocus TextView from VerticalGridItem.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="#dimen/live_category_header_height">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:fontFamily="#font/roboto_medium_500"
android:text="#string/str_dashboard_live_tv"
android:textColor="#color/common_text_color"
android:textSize="#dimen/live_category_header_text_size"
android:focusable="true"/>
</RelativeLayout>
<com.multiiptv.m3u.xstream.views.LiveVerticalGridView
android:id="#+id/live_category_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="#dimen/live_category_lr_margin"
android:clipToPadding="false"
android:layout_marginTop="#dimen/live_category_header_grid_margin_tb"
android:layout_marginBottom="#dimen/live_category_header_grid_margin_tb"
android:layout_marginEnd="#dimen/live_category_lr_margin" />
</LinearLayout>
Try adding the following statements to the TextView element:
android:focusable="true"
android:focusableInTouchMode="true"
app:focusOutEnd="true"
app:focusOutFront="true"
If that does not work, please post your presenter code.
Related
Recently i have encounterd a problem. My linear layout where my edit text and image button is in is overlapping with my toolbar and my scroll view. I've tried other things like layout_below etc and nothing worked. Groupchat.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".GroupChatActivity"
android:orientation="vertical">
<include
android:id="#+id/group_chat_bar_layout"
layout="#layout/app_bar_layout">
</include>
<ScrollView
android:id="#+id/my_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/group_chat_bar_layout"
android:layout_above="#+id/myLinearLayout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/group_chat_text_display"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textAllCaps="false"
android:textSize="20sp"
android:textColor="#android:color/background_dark"
android:layout_marginStart="2dp"
android:layout_marginEnd="2dp"
android:layout_marginBottom="50dp"/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/myLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="#+id/input_group_message"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:hint="Write message..." />
<ImageButton
android:id="#+id/send_message_button"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:src="#drawable/send_message" />
</LinearLayout>
This is how the preview of the groupchat.xml file looks in Android Studio:
enter image description here
This was how the app looked with this code.
This are the results
Just in case, this is the code of my toolbar: Appbarlayout.xml
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
It in a seperate xml because i'm using it for other activities in my app to thats why theres ang include in th Groupchat.xml
ALSO I AM FOLLOWING THIS TUTORILA. I suggest you go ther and see it because that is what i followed.
go to this video
Thank you.
The problem is with layout placements. your LinearLayout with ID: myLinearLayout is not aligned anywhere in RelativeLayout that's why it is getting rendered on top of the screen. make following changes and your good to go.
in your LinearLayout with id: myLinearLayout, add this line:
android:layout_alignParentBottom="true"
like this:
<LinearLayout
android:id="#+id/myLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
Add
android:layout_below="#+id/group_chat_bar_layout"
this line to LinearLayout
<LinearLayout
android:id="#+id/myLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/group_chat_bar_layout"
android:orientation="horizontal">
<EditText
android:id="#+id/input_group_message"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:hint="Write message..." />
<ImageButton
android:id="#+id/send_message_button"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:src="#drawable/bkg" />
</LinearLayout>`
I set the ScrollView in my LinearLayout. I want a TextView to scroll. I tried to use ScrollView in xml like this. But, it's not working.
<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:orientation="vertical"
android:padding="8dp"
tools:context=".SubpagesLayout.ReportResult">
<!-- first scrollView -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/edit_corner_blue"
android:gravity="center"
android:text="#string/personalInformation"
android:textColor="#android:color/white" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/birthDate" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" TestData" />
</LinearLayout>
<!-- second scrollView -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textOphthalmoscopy"
android:layout_width="match_parent"
android:layout_height="80dp"
android:text="standard instrth various settings that allow focusing and adjustment of the light source to accommodate the viewer and to evaluate various features of the fundus." />
</ScrollView>
</LinearLayout>
</ScrollView>
</LinearLayout>
I tried another way like this, but it's still not working too.
android:maxLines = "AN_INTEGER"
android:scrollbars = "vertical"
I used
myTextView.setMovementMethod(new ScrollingMovementMethod());
So how to let TextView to scroll? If it is the second ScrollView.
You might consider using a NestedScrollView along with a ListView for showing the scrollable TextView.
The ListView will have a fixed size so that it'll not take the total height of the items inside.
So the layout may look like this.
<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:orientation="vertical"
android:padding="8dp"
tools:context=".SubpagesLayout.ReportResult">
<!-- first scrollView -->
<NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/edit_corner_blue"
android:gravity="center"
android:text="#string/personalInformation"
android:textColor="#android:color/white" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/birthDate" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" TestData" />
</LinearLayout>
<ListView
android:layout_width="match_parent"
<!--set a fixed height-->
android:layout_height="80dp"
.. Other attributes
</ListView>
</LinearLayout>
</NestedScrollView>
</LinearLayout>
And the list item of the ListView may contain the TextView you want to scroll. Set the height of the TextView to wrap_content.
<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:orientation="vertical"
android:padding="8dp"
tools:context=".SubpagesLayout.ReportResult">
<TextView
android:id="#+id/textOphthalmoscopy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="standard instrth various settings that allow focusing and adjustment of the light source to accommodate the viewer and to evaluate various features of the fundus." />
</LinearLayout>
Now your ListView will have a single item and this will scroll with the default behaviour of list.
The whole layout will be scrolled via NestedScrollView.
Hope that helps!
Having a scrollView inside another scrollView is not a good prictice but ant a you check below links it may fix you problem.
Solution 1
Solution 2
I put a textview inside the header of a gridview but if I need to scroll the textview it not scroll, instead scroll the gridview.
This is the code:
<GridWithHeader
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/gridWithHeader"
android:numColumns="2"
android:focusableInTouchMode="true"
android:nestedScrollingEnabled="true"
android:focusable="true" />
And this is the content of header
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:id="#+id/row_2"
android:weightSum="1">
<TextView
android:id="#+id/text_header_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
where is the error or how can I solve the problem?
try to delete from "GridWithHeader" android:focusableInTouchMode and android:focusable="true" and add them to you Textview like this:
<TextView
android:id="#+id/text_header_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:fadeScrollbars="false"
android:scrollbars="vertical" >
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.
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