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.
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 got a PNG image and i want to make it my notification icon that appears on receiving any notifications i dont want it to be grey and white and idea how to achieve that ?
FB and youtube notifications icons are colored
My code
notificationBuilder.SetContentTitle("My-App")
.SetSmallIcon(Resource.Drawable.My_PNG_ICON)
.SetContentText(messageBody)
.SetAutoCancel(true)
.SetShowWhen(false)
.SetContentIntent(pendingIntent);
i used this link with my PNG image but it gives out a white and grey icons Link
On the notificationBuilder call chain, there should be a method called SetColor. Use that when trying to set notification title/icon color.
notificationBuilder.SetContentTitle("My-App")
.SetSmallIcon(Resource.Drawable.My_PNG_ICON)
.SetContentText(messageBody)
.SetAutoCancel(true)
.SetShowWhen(false)
.SetContentIntent(pendingIntent)
.SetColor(new Color().ToArgb()); // NEW LINE TO SET COLOR
You may need this line as well, but test to make sure
.SetColorized(true)
notificationBuilder.SetSmallIcon can not show the real color, you can custom a RemoteViews to use it for notificationBuilder. Then can show what your wants.
The sample code as follow:
RemoteViews contentViews = new RemoteViews(PackageName, Resource.Layout.custom_notification);
contentViews.SetImageViewResource(Resource.Id.icon, Resource.Drawable.heart_save);
contentViews.SetTextViewText(Resource.Id.tv_left, "Custom title");
contentViews.SetTextViewText(Resource.Id.tv_right, "Custom content");
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);
Notification notification = notificationBuilder.SetOngoing(true)
.SetSmallIcon(Resource.Drawable.check)
.SetContentTitle("App is running in background")
.SetPriority(1)
.SetContent(contentViews) // here add custom RemoteViews
.SetCategory(Notification.CategoryService)
.Build();
StartForeground(Constants.SERVICE_RUNNING_NOTIFICATION_ID, notification);
custom_notification.xml in layout folder:
<?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="48dp"
android:orientation="vertical"
android:paddingStart="48dp"
android:paddingEnd="48dp">
<ImageView
android:id="#+id/icon"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentStart="true"
android:src="#android:drawable/ic_lock_idle_alarm" />
<TextView
android:id="#+id/tv_left"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:gravity="center_vertical"
android:text="Left" />
<TextView
android:id="#+id/tv_right"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:gravity="center_vertical"
android:text="Right" />
</RelativeLayout>
The effect:
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 can populate the view for my ViewLabel in Nutiteq but I can't set right text in the text views of this Layout .
My code is following
//Setting Popup Label if we click the area
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View labelView = inflater.inflate(R.layout.popup_field, null);
//In order to get a dynamic "redimensionable" Ballon aka ViewLabel
labelView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
labelView.layout(0, 0, labelView.getMeasuredWidth(), labelView.getMeasuredHeight());
//labelView.measure(400, 400);
//labelView.layout(100, 100, 400, 400);
Log.info("drawField:: Nach Label fieldLabel = new ViewLabel... ");
LinearLayout lLayout = (LinearLayout)labelView.findViewById(R.id.layout1);
lLayout.setBackgroundColor(Color.RED);
TextView farmNameTV = (TextView)labelView.findViewById(R.id.farmName);
TextView areaTV = (TextView)labelView.findViewById(R.id.area);
TextView statusTV = (TextView)labelView.findViewById(R.id.status);
farmNameTV.setTextColor(Color.BLACK);
farmNameTV.setText("Farm CacoCaCoca");
areaTV.setTextColor(Color.BLACK);
String areaString = "12.34"
areaTV.setText("Area "+areaString);
statusTV.setTextColor(Color.BLACK);
String statusString = "Status:::qwertzuiopasdfghjklyxcvbnm";
statusTV.setText(statusString);
*What you can see red is my inflated View.
R.layout.popup_field looks like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/farmName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/farmName"/>
<TextView
android:id="#+id/area"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/area"/>
<TextView
android:id="#+id/status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/status"/>
where strings are
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Nutiteq3D</string>
<string name="area">Area</string>
<string name="status">Status</string>
<string name="farmName">Farm Name</string>
</resources>
Have anyone done this task already? Can anyone help me to find out my error(s)?
With MapView of google Api is easy but I develop this with Nutiteq and just pure Activities, so, NO fragments and to inflate we typically need a ViewGroup and this ViewGroup under G-Api would be MapView so inherits from ViewGroup but in Nutiteq is not like this, MapView of Nutiteq inherits of android.view and I can't casting, I can just assign as ViewGroup a null in the call of inflateas you can see.
So, people, I'd be very thankful for your help.
Kind Regards
Solved!
It didn't have to do with ViewLabel but the normal Android.View, I wanted to assign Text to TextView's after I declared my resizable View and therefore it didn't work fine.
So the solution is writing all of tv.setText above
labelView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
labelView.layout(0, 0, labelView.getMeasuredWidth(), labelView.getMeasuredHeight());