I'm trying to draw a centered vertical line in a scrollview. I have got two galaxy 2s one with the Android version 4.2.2 and the other with the version 2.3.7.
My results as far only works under the android version 4.2.2
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<View
android:layout_width="4dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#000000" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test text" />
</RelativeLayout>
</FrameLayout>
</ScrollView>
While using the android version 2.3.7 the view (line in the middle) is no draw.
Does anyone knows whats the problem running android 2.3.7?
I didn't find a xml only solution.
My xml looks like. Note that the view has a fixed height which will be replaced in the activity.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/ManualStartTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Start" />
<RelativeLayout
android:id="#+id/CenterRelativLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ManualNoCardTableRow" >
<View
android:id="#+id/ManualTopGrayLine"
android:layout_width="1dp"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:background="#000000" />
<TextView
android:id="#+id/ManualStepTreeHeaderTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ManualStepTreeButton"
android:layout_marginLeft="3dp"
android:layout_marginTop="15dp"
android:layout_toRightOf="#+id/ManualTopGrayLine"
android:gravity="right"
android:text="3) Verifizieren" />
<TextView
android:id="#+id/ManualStepTreeBodyTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/ManualStepTreeHeaderTextView"
android:layout_below="#+id/ManualStepTreeHeaderTextView"
android:layout_marginLeft="3dp"
android:text="Lorem alfpha alsda a,si ljkasoi kjasbas asdop1 ,aspo9ij aslkdja9s oaisdjas0pd oasdn0p9m asd0p9" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/CenterRelativLayout"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:orientation="vertical" >
<!-- some other content -->
</LinearLayout>
</RelativeLayout>
</ScrollView>
the xml generates the following view.
If you want to have a dynamically height of you line (view) you can add the following method to your activity. Which will set the height of the line to the same height as the RelativeLayout.
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus == true) {
View manualTopGrayLine = findViewById(R.id.ManualTopGrayLine);
RelativeLayout rlayout = (RelativeLayout) findViewById(R.id.CenterRelativLayout);
RelativeLayout.LayoutParams layoutParams = (android.widget.RelativeLayout.LayoutParams) manualTopGrayLine.getLayoutParams();
layoutParams.height = rlayout.getHeight();
manualTopGrayLine.setLayoutParams(layoutParams);
}
}
Related
I am trying to build my first Amazon Fire TV app using Android Lean back library. I want to customise the BrowseFragment to look like the image shown below.
I tried setting a custom layout as below.
#Override public View onInflateTitleView(LayoutInflater inflater, ViewGroup parent,
Bundle savedInstanceState) {
View title = inflater.inflate(R.layout.custom_title_view, parent, false);
titleImageView = (AppCompatImageView) title.findViewById(R.id.title_content_thumbnail);
return title;
}
but the resulting layout is showing as shown below, with a transparent TitleView and the list rows are showing below that. Please suggest a better approach to make the UI looks similar to the first image. Couldn't find anything that could implement this.
So, I have solved this somehow. My activity_main.xml looks like this.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/default_background"
android:orientation="vertical"
>
<fragment
android:id="#+id/title_layout"
android:name="com.kalpnik.vrdevotee.fragment.MainTitleFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentTop="true"
android:layout_weight="1"
/>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_fragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="#+id/title_layout"
android:layout_weight="1"
tools:deviceIds="tv"
/>
</LinearLayout>
In the FrameLayout I will load a fragment which extended from BrowseFragment, so this gives me the necessary rows.
And at the top, I am loading MainTitleFragment which is extended from Fragment and the layout looks like below.
fragment_main_title.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="#000000"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#color/icon_background"
android:orientation="vertical"
android:paddingTop="16dp"
>
<TextView
android:id="#+id/title_content_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
tools:text=""
android:textColor="#color/colorPrimaryDark"
android:textSize="28sp"
android:textStyle="bold"
/>
<TextView
android:id="#+id/title_content_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="16dp"
android:ellipsize="end"
android:text=""
android:textSize="15sp"
/>
</LinearLayout>
<FrameLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
>
<android.support.v7.widget.AppCompatImageView
android:id="#+id/title_content_thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
/>
<View
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:background="#drawable/transparent_bg"
/>
<View
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="bottom"
android:background="#drawable/transparent_bg_bottom"
/>
</FrameLayout>
</LinearLayout>
And this worked for me. Hope this helps.
I have a LinearLayout which I'm trying to make VISIBLE, then GONE, then VISIBLE again. However after making it GONE, it doesn't become visible again. As a note, it works fine if I make it INVISIBLE: it appears and disappears with no problem.
These are my files:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/noconnectionll"
android:visibility="gone"
android:padding="#dimen/node_default_spacing"
android:background="#color/category_no_internet"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="#string/no_internet_short"
android:textColor="#fff"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/no_connection_retry"
android:text="#string/try_again"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<ListView
android:dividerHeight="0dp"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:id="#+id/spinner_wrapper"
tools:visibility="visible"
android:visibility="invisible"
android:background="#a0ffffff"
android:gravity="center_horizontal|center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/spinner"
android:src="#drawable/ic_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/category_loading"
android:text="#string/loading"
android:textColor="#000"
android:padding="#dimen/activity_padding"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
This is the method I'm using to show/hide:
private void hideOrShowLoading(final boolean show) {
final ViewGroup spinnerWrapper = (ViewGroup)ll.findViewById(R.id.spinner_wrapper);
final View spinner = ll.findViewById(R.id.spinner);
if (show) {
spinnerWrapper.setVisibility(View.VISIBLE); // Not working after being set to GONE previously
final Animation rotation = AnimationUtils.loadAnimation(getContext(), R.anim.rotate);
rotation.setFillAfter(true);
spinner.startAnimation(rotation);
} else {
spinnerWrapper.setVisibility(View.GONE);
spinner.clearAnimation();
}
}
Any tips? Could it have something to do with the ListView above it having a height of 0 and a weight of 1?
Thanks
Update
I also tried the following after the if (show) block, with no luck:
listview.invalidate();
spinnerWrapper.invalidate();
ll.invalidate();
ll.requestLayout();
ll is the LinearLayout that contains both.
While I believe this is caused by the layout_weight=1 property, I wasn't able to properly fix this.
The following hack did work. Basically, I'm surrounding the spinnerWrapper in another linear layout which is always visible.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/noconnectionll"
tools:visibility="visible"
android:visibility="gone"
android:padding="#dimen/node_default_spacing"
android:background="#color/category_no_internet"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="#string/no_internet_short"
android:textColor="#fff"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/no_connection_retry"
android:text="#string/try_again"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<ListView
tools:background="#d496d4"
android:dividerHeight="0dp"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<!-- Weird bug with layout_weight=1 on the listview above means we need this linearlayout -->
<LinearLayout
android:background="#0ca917"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/spinner_wrapper"
android:background="#a0ffffff"
android:gravity="center_horizontal|center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/spinner"
android:src="#drawable/ic_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/category_loading"
android:text="#string/loading"
android:textColor="#000"
android:padding="#dimen/activity_padding"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
This is not working on my phone but I can see it in the Android Studio Design mode window. I need to place a LinearLayout or any view actually just below the listView. But I can't see it, only the listView fitting the whole height
<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:id="#+id/local_detalle_relative_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="android.buendia.cl.pritz.fragments.locales.LocalDetalleFragment">
<view
android:id="#+id/banner"
class="com.android.volley.toolbox.NetworkImageView"
android:layout_width="match_parent"
android:layout_height="80dp"
android:scaleType="centerCrop"
app:srcCompat="?android:attr/textSelectHandleLeft" />
<TextView
android:id="#+id/current_category"
style="#style/current_category"
android:layout_below="#+id/banner"
android:text="TextView" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/current_category">
<ListView
android:id="#+id/list_view_local_detalle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<LinearLayout
android:id="#+id/cart_bar"
style="#style/cart_bar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="#+id/cart_status"
style="#style/cart_bar_status"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:text="TextView" />
<Button
android:id="#+id/cart_next"
style="#style/cart_bar_next"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/cart_bar_next_button_text" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
Set android:layout_below="#+id/list_view_local_detalle" for LinearLayout
Note : If you'r using weight for vertical linear layout then height must be 0 dp and if using for horizontal linear layout then width must be 0dp.
I'm using the below xml for dialogue in android.
However the background only applies on ViewPager, does not apply on linearlayout under the view pager. but that linearlayout is always white..
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/AA"
android:layout_width="wrap_content"
android:layout_height="560dp"
android:background="#fcfcfc"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="#+id/BBB"
android:layout_width="match_parent"
android:layout_height="333dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="85dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="18dp"
android:orientation="vertical">
<LinearLayout
android:id="#+id/dialog_page_mark"
android:layout_width="match_parent"
android:layout_height="18dp"
android:gravity="top|center_horizontal"
android:orientation="horizontal" />
<TextView
android:id="#+id/dialog_page_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="15dp"
android:visibility="gone" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="67dp"
android:gravity="end|center_vertical"
android:orientation="horizontal"
android:paddingEnd="24dp" >
<Button
android:id="#+id/CCCC"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:focusable="true"
android:gravity="center"
android:minWidth="0dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:textAllCaps="true"
android:textSize="16dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
And, in the code, I call these codes,
WindowManager.LayoutParams wm = new WindowManager.LayoutParams();
wm.copyFrom(this.getWindow().getAttributes());
wm.width = LayoutParams.WRAP_CONTENT;
wm.height = LayoutParams.WRAP_CONTENT;
getWindow().setAttributes(wm);
getWindow().setBackgroundDrawableResource(R.color.FCFCFC);
Am I wrong??
R.color.FCFCFC = "#fcfcfc"
Why the backgound color setting is not working the linearlayout under ViewPager?? Help me... Please..
Assign an id for your LinearLayout
Using below code to get instance:
LinearLayout ll = (LinearLayout) findViewById(R.id.yourLinearLayout);
Using below code to change background color:
ll.setBackgroundColor(getResources().getColor(R.color.FCFCFC));
I am solving a problem with image and text in one scroll view. The main problem is, that I get different image height from server side . But the place with image should be all the time same.
Now the height of image place is dynamic. The text should be scrollable with the image.
Is there any possibility how to make the image height static?
Thank you!
EDIT
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/article_gallery"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="4" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="#+id/article_image_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="#drawable/sipka_l" />
<ImageView
android:id="#+id/article_image"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
<ImageView
android:id="#+id/article_image_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="#drawable/sipka_p" />
</LinearLayout>
<TextView
android:id="#+id/image_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/tran_dark_gray"
android:gravity="center"
android:padding="#dimen/size_8"
android:textAppearance="#style/xsmallLight" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="6"
android:background="#color/opaq_light"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="#dimen/size_16" >
<TextView
android:id="#+id/article_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/size_12"
android:textAppearance="#style/normalBold" />
<TextView
android:id="#+id/article_body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="#style/xsmall" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</FrameLayout>
If you declare the ImageView with a fixed width and height it will remain static all the time.
Try something like:
<ImageView
android:id="#+id/imageView1"
android:layout_width="50dp"
android:layout_height="50dp"
/>
Put this ImageView inside a ScrollView and ofcourse put your TextView inside the same ScrollView.
you can use layout weights for your linearlayout. Set the width to 0 and let the weight determine actual size. Setting weight to 0.33 each gives each images 1/3 of the screen.
Or you could set one to 0.5 and the others to 0.25 each or whatever makes sense for your app.
Set the 3 images as:
<ImageView
android:id="#+id/article_image_back"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:layout_gravity="center_vertical"
android:src="#drawable/sipka_l" />