TextView is not Displayed until VideoView start playing - android

I wrote an android application which has to two views, VideoView above TextView(which is inside a ScrollView), I met a problem that until the VideoView starts playing a video, the TextView is not displayed and I have a blackscreen, and this might take a long time, since the command to start the video is received from a client via RPC. Could someone please help pointing the problem, either by editing main.xml or using code?
My main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<VideoView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/videoview"
/>
<ScrollView
android:id="#+id/ScrollView01"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TextView
android:layout_width="wrap_content"
android:id="#+id/textview"
android:layout_height="wrap_content"
android:text="Wellcome"
/>
</ScrollView>
</LinearLayout>
And the import in my activity is only:
setContentView(R.layout.main);

i don't think u will have problem in using relative layout like this
<?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"
android:orientation="vertical">
<VideoView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/videoview"
android:layout_above="#+id/ScrollView01"
/>
<ScrollView
android:id="#+id/ScrollView01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true"
>
<TextView
android:layout_width="wrap_content"
android:id="#+id/textview"
android:layout_height="wrap_content"
android:text="Wellcome"
/>
</ScrollView>
</RelativeLayout>

Related

Unable to display the ImageView in FrameLayout (Android)

I had made a simple camera app and was thinking about customizing the view. Currently, I've been stuck with a problem with the ImageView not being able to be displayed on the top of the framelayout. Is there something wrong with the xml code below ? Or should I set some parameter in the code ? All I want to do is to display the Imageview above the framelayout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right|center_vertical">
<ImageView
android:id="#+id/button_capture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/shot_dot_icn" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
Try this layout, I am not sure if I understand your requirement though.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="#+id/button_capture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/shot_dot_icn" />
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right|center_vertical">
</LinearLayout>
</FrameLayout>
</LinearLayout>
I solved the problem with the script below. All I had to do was to set the bringToFront() to the ImageView to set the view on top of the Framelayout.
ImageView captureButton = (ImageView) findViewById(R.id.button_capture);
captureButton.bringToFront();

Android LinearLayout with Button and FrameLayout using the Maximum Height

I am trying to make a layout where there are a LinearLayout and inside it I want a FrameLayout and a button.
I want the button to use the bottom of the linearlayout and to use the maximum width and the enough height for the button, using wrap content.
The other component, the FrameLayout I want to use it the remaining part of the screen.
How can I do it?
Here it the layout so far..
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:onClick="snapIt"
android:text="#string/Capture" />
</LinearLayout>
Is not showing the button :s
Thanks alot in advance ;)
Better to work out with relative layout with button aligned to parent bottom and your frame layout above it occupying the rest space of the screen.Like this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/button_capture"/>
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="snapIt"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
use the following xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="snapIt"
android:layout_alignParentBottom="true"
android:text="capture" />
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button_capture"
/>
</RelativeLayout>
i am just trying to make these layout, after compare my layout code and your layout code, i find a different code, there is in my code. Did you missing it or just move it away cause it useless from the layout code ?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<FrameLayout
android:id="#id/flayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/hello_world">
</FrameLayout>
</LinearLayout>

Set multiple items inside a tab off Android's Tabhost

For the app I'm working on I'd like to have 3 tabs with different elements in them.
I tried searching for a way to accomplish this but I can't seem to find an example of what I need.
Basicly I want this:
Tab 1, contains 4 buttons and a textview
Tab 2, contains an scrollable imageview
Tab 3, contains an webview
I would like to solve this problem without the use of activity's because all 3 tabs need to access the same data.
Currently I use this xml as layout:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/photoLayout">
<Button
android:text="#string/photoButton"
android:layout_column="0"
android:id="#+id/photoButton"
android:textSize="10dp" />
<Button
android:text="#string/locateButton"
android:layout_column="1"
android:id="#+id/locateButton"
android:textSize="10dp" />
<Button
android:text="#string/cropButton"
android:layout_column="2"
android:id="#+id/cropButton"
android:textSize="10dp" />
<Button
android:text="reset"
android:layout_column="3"
android:id="#+id/resetButton"
android:textSize="10dp" />
<ScrollView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="fill_parent"
android:layout_height="370dp"
android:id="#+id/scrollView1"
android:fillViewport="true">
<TextView
android:text="Text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/textView1" />
</ScrollView>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/webviewLayout">
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/webView1" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/imageLayout">
<ScrollView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="fill_parent"
android:layout_height="412dp"
android:id="#+id/scrollView2"
android:fillViewport="true">
<ImageView
android:src="#android:drawable/ic_menu_gallery"
android:layout_column="0"
android:id="#+id/imageView1"
android:layout_height="411.6dp"
android:layout_width="316.7dp"
android:scaleType="centerInside" />
</ScrollView>
</LinearLayout>
</FrameLayout>
</LinearLayout>
The problem with this is that I get a runtime exception saying:
Java.Lang.RuntimeException: Binary XML file line #1: You must supply a layout_width attribute.
Any help to solve this issue will be appreciated!
To answer the exception thrown, you need to specify layout_width and layout_height in every single elements you declared, which in your case, you did not specify any on those buttons.
But to express my curiosity, I believe you should anyhow make it in separate activities and separate layouts, "same data" can always be passed around using some extras I believe.

how to put textview on top of a datepicker

im trying to build a form, with a textview and a datepicker,something like:
|Date: |
|datePickerHere|
the problem is i think i have the "same" code as the developer guide but it isnt working. it always ends up like:
|Date: datePickerHere|
Heres the code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:text="#string/data_label"/>
<DatePicker
android:id="#+id/data"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
Change
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content">
to
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
Linear Layouts will default to horizontal orientation if you don't specify the "android:orientation" tag. You must specify it as vertical to achieve what you want

Android textView scroll

I have been trying to develop an android app that contain an activity which is scrollable
and inside the activity, I have 2 textView which I want them to be scrollable as well.
My problem is that
whenever I touch inside the textView the scrolls show up but the main activity part which is the linearLayout directly steel the focus and no longer the textView scroll
the way I have it now is setup for the textView to scroll in the xml file I have done that.
and if I keep raising my finger and put it back on the screen trying to scroll the textView I can move a little bit but as I said, the layout that contains the textView capture the focus and leave me unable to scroll the textView.
I hope I did explain my problem very well.
Please any suggestion to help.
let me explain how the app is built first
first part is: the main(first) activity is a tabHost
which I defined as scrollable
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="422dp" >
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="63dp" >
</TabWidget>
</LinearLayout>
</ScrollView>
</TabHost>
where I am having problem with is this activity
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/light_gray_color"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:weightSum="1"
android:orientation="vertical"
android:baselineAligned="false">
<LinearLayout
android:id="#+id/linearLayout3"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.04">
<TextView
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#color/black_color"
android:layout_gravity="center_horizontal"
android:text="#string/display_label"
android:id="#+id/display_label">
</TextView>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.83"
android:baselineAligned="false"
android:orientation="horizontal" >
<ScrollView
android:id="#+id/english_scrollView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.03" >
<TextView
android:id="#+id/display_english_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2px"
android:layout_marginRight="2px"
android:layout_weight="0.03"
android:background="#drawable/black_rectangle"
android:focusable="true"
android:paddingLeft="2px"
android:paddingRight="2px"
android:scrollbars="vertical"
android:textColor="#color/black_color" />
</ScrollView>
<ScrollView
android:id="#+id/translation_scrollView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.03" >
<TextView
android:id="#+id/display_translation_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2px"
android:layout_marginRight="2px"
android:layout_weight="0.03"
android:background="#drawable/black_rectangle"
android:focusable="true"
android:paddingLeft="2px"
android:paddingRight="2px"
android:scrollbars="vertical"
android:textColor="#color/black_color" />
</ScrollView>
</LinearLayout>
</LinearLayout>
I guess you should cut <ScrollView> out of the first xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="422dp" >
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="63dp" >
</TabWidget>
</LinearLayout>
</TabHost>
My understanding is that you have a vertically scrolling activity, which contains two vertically scrolling text views? If so, you can't do it. Its not just a poor design choice, its literally impossible to tell which view the user intends to scroll when they make swipe motion. You can have horizontal scrolling inside a vertically scrolling view, or vice versa. You can't have horizontal scrolling inside horizontal scrolling or vertical scrolling inside vertical scrolling.
I believe this is mentioned in the listview talk in the 2010 google io conference: http://www.youtube.com/watch?v=wDBM6wVEO70

Categories

Resources