I am trying to set a white line in Android Studio.
I have the whiteLine.png stored in drawable-hdpi. I have set it in the Main Activity. I have no idea why it is now showing in the emulator.
Tried on multiple API version, nothing changes.
Why is the whiteLine ImageView not working?
IMAGE IN ANDROID DESIGN
IMAGE IN EMULATOR
MAIN ACTIVITY CODE
whiteLine = (ImageView) findViewById(R.id.whiteLine);
whiteLine.setImageResource(R.drawable.whiteline);
XML
<ImageView
android:id="#+id/whiteLine"
android:layout_width="wrap_content"
android:layout_height="7dp"
android:layout_marginTop="265dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/whiteline" />
Related
I created a Tabbed Activity template project using Android Studio.
Then I created a LinearLayout with a nested TextView on it:
<LinearLayout
android:id="#+id/updateView"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_marginTop="707dp"
android:orientation="vertical">
<TextView
android:id="#+id/updateTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="right"
android:text="TextView" />
</LinearLayout>
This view is shown on preview, but there's none of it in the built app.
When I try to get a reference to it from my code:
LinearLayout lastUpdate = findViewById(R.id.updateView)
I get null in runtime.
So, how can I modify the code?
Preview screenshot
I solved my problem by moving xml code of LinearLayout upper, than code of AppBarLayout, and modification of dynamic pixels (dp) of ViewPager and my textView
In my Android app, I have a WebView and 6 buttons inside a ConstraintLayout. The WebView should zoom fully out on start, but it instead goes only to the width of the device.
The WebView is set up like layout_width="fill_parent" layout_height="0dp", which should be match_constraint
My current code is:
web.getSettings().setSupportZoom(true);
web.getSettings().setBuiltInZoomControls(true);
web.getSettings().setDisplayZoomControls(false);
web.getSettings().setLoadWithOverviewMode(true);
web.getSettings().setUseWideViewPort(true);
WebView XML:
<WebView
android:id="#+id/webView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:clickable="false"
app:layout_constraintBottom_toTopOf="#id/button1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible">
</WebView>
I expect the WebView to show the full image/video, but it's still scrollable in horizontal direction, sometimes it even puts black bars below and above it.
Video demonstation: https://youtu.be/ucmLNksNGRI
i trying to get a layout just like the image below for a game in android studio
currently my xml is
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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="com.dreacot.testmymemory.Game">
<ImageView
android:id="#+id/imageView"
android:layout_width="72dp"
android:layout_height="115dp"
app:srcCompat="#drawable/backside"
tools:layout_editor_absoluteX="53dp"
tools:layout_editor_absoluteY="136dp" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="72dp"
android:layout_height="115dp"
app:srcCompat="#drawable/backside"
tools:layout_editor_absoluteX="156dp"
tools:layout_editor_absoluteY="136dp" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="72dp"
android:layout_height="115dp"
app:srcCompat="#drawable/backside"
tools:layout_editor_absoluteX="266dp"
tools:layout_editor_absoluteY="136dp" />
<ImageView
android:id="#+id/imageView6"
android:layout_width="72dp"
android:layout_height="115dp"
app:srcCompat="#drawable/backside"
tools:layout_editor_absoluteX="53dp"
tools:layout_editor_absoluteY="285dp" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="72dp"
android:layout_height="115dp"
app:srcCompat="#drawable/backside"
tools:layout_editor_absoluteX="156dp"
tools:layout_editor_absoluteY="285dp" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="72dp"
android:layout_height="115dp"
app:srcCompat="#drawable/backside"
tools:layout_editor_absoluteX="266dp"
tools:layout_editor_absoluteY="285dp" />
i want more cards to be added on the next level eg lvl 2
do i need to make several layouts for each level?
also i want each card to show its face when it is clicked
and finally i feel i am not doing the right thing as i feel xml files cannot be called into the gameplay is there a better way to do this layout(maybe programmatically)?
could anyone help?
The way you are doing it is not the proper way to do it, In this way maybe you can achieve this for 6 cards. What if you have let's say 100 cards or may be 1000, will you add 100 images in Layout and get reference of 100 images in Activity and set Click Listeners and animations to turn the side on 100 images?
Use "GridView" and Adapter for your views, it will do your work with ease.
Check this: https://developer.android.com/guide/topics/ui/layout/gridview.html
You have to do it programmatically.
1. Use RecyclerView with GridLayoutManager to show your card as grid style.
2. Create a layout with just a CardView with single ImageView for your single card item.
3. Create an custom RecyclerView.Adapter<> and use it with RecyclerView to populate your card data on CardView.
4. Add onItemClick listener to Adapter to flip to the specific Card item and do something as per your needs.
Here are some useful links about RecyclerView:
Android RecyclerView with GridLayoutManager Example
Android GridLayoutManager with RecyclerView in Material Design
Simple Android grid example using RecyclerView with GridLayoutManager
Here is a good library for CardView animation.
Hope this will help~
I've been working on a simple java application, and wanted to add a logo as the homescreen is fairly empty. I tried using an image view, and after it didn't work I googled tutorials to make sure I was initiating it correctly. I didn't see any difference, but the actual image wouldn't load.
Xml code for image view:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src = "#drawable/logo"
android:layout_gravity="center"
android:contentDescription="#string/logo"
android:layout_below="#+id/textView"
android:layout_above="#+id/txtBody"
android:layout_alignRight="#+id/txtBody"
android:layout_alignEnd="#+id/txtBody"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:visibility="visible"
android:maxHeight="600dp"
android:maxWidth="600dp"
android:minHeight="100dp"
android:minWidth="100dp"
android:clickable="false" />
And here's a picture of the layout preview (With an arrow pointing to the outline of where it should be, and the resource circled in the correct folder) along with a picture of the logo
Any dice if you add
android:scaleType="fitCenter"
android:adjustViewBounds="true"
Edit: also are we sure nothing is overlapping it?
I have imageview with resolution of 430x871 in folders xxhdpi, xhdpi and hdpi. But when I run app, on 5" Xperia Z (xxhdpi) screen it works normally (1. picture) but on 4.7" Amazon Phone (xhdpi) it's smaller (2. picture). Altough when I run it on Amazon Fire HD 8.9 or 7 or 6, (all xdpi) it works too...
How can I stretch in on that Amazon Phone?
Here is XML code of the Imageview:
<ImageView
android:id="#+id/matter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:gravity="center"
android:src="#drawable/matter"
/>
if aspect ratio is not important for you use:
android:scaleType="fitXY"
but if yes try this:
android:scaleType="fitCenter"
and also change this:
android:layout_height="match_parent"
There's a property called :
android:scaleType="fitXY"
inside ImageView tag.