Noob to Java so I have limited knowledge. I have 2 RelativeLayouts which will hold images of a 13 card hand. One for all the cards and one slightly offset which show which cards can be played. Xml is fairly straight forward
<!--Player viewable cards-->
<RelativeLayout
android:orientation="vertical"
android:layout_width="200dp"
android:layout_height="680dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="100dp"
android:layout_marginLeft="15dp"
android:id="#+id/rlUserViewCards">
<ImageView
android:layout_width="100dp"
android:layout_height="85dp"
android:src="#drawable/c001"
android:rotation="90"
android:tag="1"
android:id="#+id/card1"
android:clickable="false">
</ImageView>
<ImageView
android:layout_width="100dp"
android:layout_height="85dp"
android:src="#drawable/c002"
android:rotation="90"
android:id="#+id/card2"
android:layout_below="#+id/card1"
android:layout_marginTop="-65dp"
android:clickable="false">
</ImageView>
and so on for 13 Images. I can then create a View of the relativelayout looping through the children making images INVISIBLE/VISIBLE, Clickable or not. Does this seem like a good approach?
If so, my problem when first setting the relativelayout is that I can do above as well as set Tag with the card value, I can't figure how to get the integer for the ImageView via findViewById.
userViewCards = (RelativeLayout) findViewById(R.id.rlUserViewCards);
userPickCards = (RelativeLayout) findViewById(R.id.rlUserPlayCards);
View v = userViewCards.getChildAt(0);
Resources res = getResources();
int resId = res.getIdentifier("s204", "drawable", getPackageName());
Drawable drawable = ResourcesCompat.getDrawable(getResources(), res.getIdentifier("s204", "drawable", getPackageName()), null);
ImageView insertImage = (ImageView) findViewById(??);
insertImage.setImageDrawable(drawable);
Can anyone point me in the right direction?
Thanks!
You can set a tag value to the imageView and recieve it in your activity as follows
<ImageView
android:layout_width="100dp"
android:layout_height="85dp"
android:src="#drawable/c001"
android:rotation="90"
android:tag="1"
android:id="#+id/card1"
android:clickable="false">
#OnClick({R.id.card1, R.id.card2, R.id.card3, R.id.card4})
public void selectedCard(View view) {
String selectedCard = view.getTag().toString();
Log.d(TAG, "Mode Selected : " + mode);
switch (Integer.parseInt(mode)) {
case Constant.Card1:
// Do something here
break;
case Constant.Card2:
// Do something here
break;
case Constant.Card3:
// Do something here
break;
case Constant.Card4:
// Do something here
}
}
Note : I am using butterknife here hence the #OnClick()
Related
can you please help me to know how can I change the text below the poster in leanback details view content without losing the position?
this is the code I used:
lb_fullwidth_details_overview_logo
<?xml version="1.0" encoding="utf-8"?><!-- This is an override of the full width details overview logo layout -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/container"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/details_overview_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:elevation="#dimen/lb_details_overview_z"
android:maxHeight="#dimen/lb_details_v2_logo_max_height"
android:maxWidth="#dimen/lb_details_v2_logo_max_width" />
<TextView
android:id="#+id/statusText"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
CustomDetailsOverviewLogoPresenter
class CustomDetailsOverviewLogoPresenter(private val entitlementStatus: String) :
DetailsOverviewLogoPresenter() {
internal class ViewHolder(view: View?) :
DetailsOverviewLogoPresenter.ViewHolder(view) {
override fun getParentPresenter(): FullWidthDetailsOverviewRowPresenter {
return mParentPresenter
}
override fun getParentViewHolder(): FullWidthDetailsOverviewRowPresenter.ViewHolder {
return mParentViewHolder
}
}
override fun onCreateViewHolder(parent: ViewGroup): Presenter.ViewHolder {
val cardView = DetailsOverviewCardView(parent.context)
val width: Int = ViewGroup.LayoutParams.WRAP_CONTENT
val height: Int = ViewGroup.LayoutParams.WRAP_CONTENT
cardView.layoutParams = MarginLayoutParams(width, height)
return ViewHolder(cardView)
}
override fun onBindViewHolder(viewHolder: Presenter.ViewHolder, item: Any) {
val row = item as DetailsOverviewRow
val cardView = viewHolder.view as DetailsOverviewCardView
val imageView = cardView.imageView
val status = cardView.statusText
status.text = entitlementStatus
imageView.setImageDrawable(row.imageDrawable)
if (isBoundToImage(viewHolder as ViewHolder, row)) {
viewHolder.parentPresenter.notifyOnBindLogo(viewHolder.parentViewHolder)
}
}
}
but now the image is not in the position it must be
You need to create a custom DetailsOverviewLogoPresenter. When you construct your FullWidthDetailsOverviewRowPresenter, the first parameter is the Presenter to use to render the description and the second one is the DetailsOverviewLogoPresenter.
In your DetailsOverviewLogoPresenter, implement onCreateView (to inflate and return the view you want to use), onCreateViewHolder (to wrap the returned view in a ViewHolder), and onBindViewHolder (to use the ViewHolder to set up the views including the image and your custom TextView's text).
The official sample has a setupAdapter method that shows how to create and use custom presenters.
I have a PreviewView instance on which i want to draw a rect based on object identifies using Firebase and Image Analyser use case.
However, unlike in Text/ SurfaceView PreviewView doesn't let any Canvas to be drawn on top of it.
What's the alternative?
Further Edits:
Tried the below earlier:
Canvas objectFrameCanvas = new Canvas();
Paint pen = new Paint();
pen.setColor(Color.RED);
pen.setStrokeWidth(8F);
pen.setStyle(Paint.Style.STROKE);
objectFrameCanvas.drawRect(100,150,200, 250, pen);
TextureView textureView = new TextureView(this);
textureView.draw(objectFrameCanvas);
mPreviewView.addView(textureView);
Create a child forviewgroup : textureView.
Make new canvas objectFrameCanvas, draw rectangle on it, then draw canvas on textureView. Then add this to view group (PreviewView)
Still doesnt give me the requisite result it should.
By the way am using this inside my ImageAnanysis usecase
imageAnalysis.setAnalyzer(executor, new ImageAnalysis.Analyzer() {....}
To draw on top of your preview, you can create a custom view which draws a rectangle with the list of RectF you give it. Here's a gist of it:
class RectOverlay constructor(context: Context?, attributeSet: AttributeSet?) :
View(context, attributeSet) {
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
// Pass it a list of RectF (rectBounds)
rectBounds.forEach { canvas.drawRect(it, paint) }
}
}
And use this custom view in your layout:
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.camera.view.PreviewView
android:id="#+id/preview_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.example.RectOverlay
android:id="#+id/rect_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Here is a good repo to check which uses CameraX and draws rectangular bounds over detected faces: https://github.com/husaynhakeem/android-playground/tree/master/FaceDetectorSample
I'm attempting to use Glide to fetch an image using HTTP and display it in AR using ARCore Sceneform. The layout file is working because the border described in it is being displayed, but the image itself is not being displayed or even fetched.
Here is my code:
View view = View.inflate(context, R.layout.test_view, null);
if (v == 2) {
//ImageView imageView = (ImageView) renderable.getView();
Glide.with(context)
.asDrawable()
.load("http://i.imgur.com/DvpvklR.png")
//.into(view);
.submit(-1,-1);
rendobject =
ViewRenderable.builder()
.setView(context, view)
.setVerticalAlignment(ViewRenderable.VerticalAlignment.BOTTOM)
//.setSizer(new FixedWidthViewSizer(0.2f))
.setSizer(new FixedHeightViewSizer(0.15f))
.build()
.thenAccept(renderable -> {
testViewRenderable = renderable;
});
Here is the layout file:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/planetInfoCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/rounded_bg"
android:gravity="center"
android:orientation="vertical"
android:padding="4dp"
/>
Here are the network permission declarations in the Manifest:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
I don't know what I'm missing/doing incorrectly.
Edit:
Here is something I also tried, but nothing is displayed after successfully scanning the augmented image:
rendobject =
ViewRenderable.builder()
.setView(context, R.layout.test_view)
.setVerticalAlignment(ViewRenderable.VerticalAlignment.BOTTOM)
.setSizer(new FixedHeightViewSizer(0.1f))
.build()
.thenAccept(renderable -> {
testViewRenderable = renderable;
ImageView imageView = (ImageView) renderable.getView();
Picasso.get()
.load("http://i.imgur.com/DvpvklR.png")
.fit()
.centerInside()
.into(imageView);
I don't see that the Glide call and the view are connected in any way. You have to load the image into the ImageView.
I trying to add a navigation title icon to my app in one of the page and the code that i have used is:
For iOS:
NavigationPage.SetTitleIcon(this, "icon.png");
For Android in the ToolBar.axml I have added a ImageView as shown below:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<ImageView
android:id="#+id/titleicon"
android:src="#drawable/UstNameIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.v7.widget.Toolbar>
The issue is that, I want my Navigtion icon to get disabled in my next Page and put a title instead of icon.
For that, I tried
For iOS:
NavigationPage.SetTitleIcon(this, null);
NavigationPage.Title="Title";
For Android, How can i achieve the change of Navigation title?
In MainActivity.cs
[Activity (Label = "Todo.Android.Android", MainLauncher = true, Icon="#android:color/transparent")]
For Title, you can set Title property in xaml or c#
To change text you just simple need to find that element by id, and set up a title:
var toolbar =
FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); // it may be simplifed
SetSupportActionBar(toolbar);
toolbar.Title = "title";
And image is under toolbar.Logo, so you can just try:
toolbar.Logo = null;
If you have some data in resources which you want to put in, you can use also:
toolbar.SetTitle();
toolbar.SetLogo();
I tried to have a scrolling image in my android app but have this error in my debugger:
Binary xml error in line 10 :inflating android widget imageview
This the xml code
<?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="#drawable/bgabout">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/aboutscroll" />
</ScrollView>
</LinearLayout>
And this is the stack trace:
08-26 11:43:58.102: E/AndroidRuntime(24553): FATAL EXCEPTION: main 08-26 11:43:58.102:
E/AndroidRuntime(24553): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.albir/com.example.albir.About}: android.view.InflateException: Binary XML file line #10: Error inflating class android.widget.ImageView
i used the guidelines and i maked same changes so now i can scroll only image that had 700*1900 px rather than this large the debuguer show this trace :exception out of memory this the code :
<HorizontalScrollView
android:id="#+id/horizontalScrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</ScrollView>
</HorizontalScroll>
the java class
public class About extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
ImageView iv = (ImageView) findViewById(R.id.imageView1);
Resources res = getResources();
BitmapDrawable bitmap = (BitmapDrawable) res.
getDrawable(R.drawable.aboutscroll);
int imgW = bitmap.getIntrinsicWidth();
int imgH = bitmap.getIntrinsicHeight();
iv.setImageDrawable(bitmap);
ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) iv.getLayoutParams();
params.width = imgW;
params.height = imgH;
}
}
i want to know if i can modify this code to show more large image
It seems as though the image you're loading is too large and is causing some sort of out of memory exception. You could try to use smaller images and put them into the appropriate folders (drawable-hdpi, drawable-mdpi etc).
If this isn't suitable for you, please read through the following guides to best understand how you should be handling large bitmaps in Android:
http://developer.android.com/training/displaying-bitmaps/index.html
Finally, you could try to find a library (like Picasso) that handles image relates things in your app..
I had this issue and spent some time pulling my hair out.
It ended up being due to the image I was trying to load was accidentally copied into the drawable-en-rIE (a locale-specific) folder instead of the top-level drawable folder.
Simply moving the source image into the drawable folder solved the issue for me.