I'm using openCV's JavaCameraView in android and i'm trying to add an image button and text view on top of it. I tried to add it from the design and the xml is:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.lama.myapplication.MainActivity">
<org.opencv.android.JavaCameraView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:gravity="center"
android:layout_marginLeft="-8dp"
android:id="#+id/java_camera_view"
tools:layout_editor_absoluteY="0dp"
app:layout_constraintLeft_toLeftOf="parent" />
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="50dp"
android:layout_height="50dp"
android:scaleType="fitCenter"
android:background="#null"
app:srcCompat="#drawable/loud" />
</android.support.constraint.ConstraintLayout>
but this didn't work and the button is not shown, how can I do it?
Related
I'm struggling with an issue with the ImageView tag. It seems to load a PNG from the drawable folder in preview, but when I run the app on my phone via the simulator the image does not show up.
Here's the XML layout for my image:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
tools:context="org.tensorflow.demo.CameraActivity" >
<Button
android:id="#+id/calButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start/Stop" />
<Button
android:id="#+id/clearButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="110px"
android:text="Clear" />
<ImageView
android:id="#+id/cView"
android:layout_width="50dp"
android:layout_height="46dp"
android:layout_marginTop="240px"
android:src="#drawable/record_circle" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="120dp"
android:layout_height="62dp"
android:layout_gravity="bottom|end"
android:background="#android:drawable/btn_dropdown"
android:spinnerMode="dropdown" />
</FrameLayout>
Here's the code in my activity to load the image as well:
ImageView circleView = (ImageView) findViewById(R.id.cView);
circleView.setImageResource(0);
Drawable circleDraw = getResources().getDrawable(R.drawable.record_circle);
circleDraw = (circleDraw);
circleView.setImageDrawable(circleDraw);
Thanks!
**I've tried using both src and background in the android:src="#drawable..." property
Try this:
<ImageView
android:id="#+id/cView"
android:layout_width="50dp"
android:layout_height="46dp"
android:layout_marginTop="240px"
app:srcCompat="#drawable/record_circle" />
Here is an example of the app namespace import:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
Note that this is the top-most layout, so it may be "LinearLayout," Or whatever you are using
I'm trying to create a trimmer bar to my video player, on design time it's everything ok but on runtime the background color of my bar disappears
trimmer_bar:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/thumbsBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
tools:background="#ab5442">
<ImageView
android:id="#+id/leftThumb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription=""
android:scaleType="fitStart"
android:src="#drawable/ic_left_thumb" />
<ImageView
android:id="#+id/rightThumb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:contentDescription=""
android:scaleType="fitEnd"
android:src="#drawable/ic_right_thumb" />
</RelativeLayout>
<ImageView
android:id="#+id/progressIndicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerVertical="true"
android:layout_marginStart="60dp"
android:contentDescription=""
android:src="#android:drawable/btn_star_big_on" />
</RelativeLayout>
main_activity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".activities.Main2Activity"
android:orientation="vertical">
<com.tomatedigital.instagram.longstories.ui.TrimmerBar
android:layout_width="match_parent"
android:layout_height="wrap_content">
</com.tomatedigital.instagram.longstories.ui.TrimmerBar>
</LinearLayout>
i cannot paste the whole code of trimmerbar.java here because it's too long as it keeps the video progress synchronized between the bar and the player... but i've searched EVERYWHERE, none of my class has any mention to setBackground or related the only layout field i handle are the margins
You set tools:background="#ab5442"(It setting just for preview), for setting backgroun in runtime set android:background="#ab5442"
tools namespace just for convinience when developing and not affecting runtime
I am trying to design as shown in below figure,i have a linear layout,inside that i am adding two images,over each image i am adding text view.But as per below code image doesnt even appear in xml file(i have added image in drawable folder),What i am missing here?Please help me..
.xml file
<?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:background="#C5C5C5">
<TextView
android:text="Desing view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView1" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="300dp"
android:id="#+id/linearLayout1"
android:background="#c5c5c5">
<ImageView
android:src="#drawable/img"
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="#+id/imageView1" />
<ImageView
android:src="#drawable/img"
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="#+id/imageView2" />
</LinearLayout>
</LinearLayout>
I am new to Java and Android and I am facing this problem:
I would like to add a photo to the top/left corner of a Rectangle. However, the ImageView of my photo gets always more space and so, it creates a blank space on top that I would not like to have. Here is a screenshot:
The code of my Layout is:
<?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:padding="25dp">
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/profile_frame" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageView1"
android:layout_centerVertical="true"
android:src="#drawable/foto_facebook_juan_mejorada" />
</RelativeLayout>
Try this:
android:scaleType="fitStart"
android:adjustViewBounds="true"
It may be because of
size of the image. If the image not fit in the space given it will add blank space.
// try this way
<?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:gravity="center">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="30dp">
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/profile_frame" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#drawable/foto_facebook_juan_mejorada" />
</FrameLayout>
</LinearLayout>
My intent is to create a list of widgets on a scroll view, with an ImageView in the centre of the screen behind them. Here is what I have, there will be more buttons when all is said and done:
<?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">
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:contentDescription="#string/description"
android:src="#drawable/myImage"
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:scaleType="centerInside" />
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="#android:color/transparent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:background="#android:color/transparent">
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/newButton"
style="#style/homeScreenButton"
android:text="#string/new_profile" />
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/loadButton"
style="#style/homeScreenButton"
android:text="#string/load_profile" />
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/calculatorButton"
style="#style/homeScreenButton"
android:text="#string/calculator" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
On eclipse's xml graphical layout interpreter, the screen is shown as expected. The same is true with the 2 different emulators that I tried, Android 2.2 and Android 4.0.3. But when I send to my actual device, Droid 4 w/Android 4.1.2 the image simply does not show up. I even tried making the ScrollView transparent (android:alpha="0") thinking that it was somehow covering the image up, but nothing. Any suggestions would be greatly appreciated.
try eliminating this line from ImageView,
xmlns:android="http://schemas.android.com/apk/res/android"
it should be present only in the RelativeLayout
so your xml file become
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:contentDescription="#string/description"
android:src="#drawable/myImage"
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:scaleType="centerInside" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="#android:color/transparent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:background="#android:color/transparent">
<Button
android:id="#+id/newButton"
style="#style/homeScreenButton"
android:text="#string/new_profile" />
<Button
android:id="#+id/loadButton"
style="#style/homeScreenButton"
android:text="#string/load_profile" />
<Button
android:id="#+id/calculatorButton"
style="#style/homeScreenButton"
android:text="#string/calculator" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
I figured it out, the code was fine. My problem was that the image was in /res/drawable but it needed to be in /res/drawable-hdpi.