I am using xamarin android.
I want to set the height for the below fragment tag programmatically.
<fragment
android:id="#+id/googlemap"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"/>
Could anyone please advice me.
Thanks in Advance.
Try this:
var mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.googlemap);
mapFragment.View.LayoutParameters.Height = 500; //The size you decide
mapFragment.View.LayoutParameters.Width = 500; //The size you decide
Related
How can I get the height of the webview based on the content loaded.
The webview seems to grow to fit the content on Android, however the webview height is always 0 on ios unless set manually.
Unfortunately I have no way of knowing what the height should be to set it manually.
I've tried nativescript-webview-interface but this does not work on ios.
Is there marshalling/code for ios to retrieve the webview height or webview scrollheight after load?
I got the answer with a simple method
html:
<WebView [src]="src" (loadFinished)="onLoadFinished($event)"></WebView>
ts:
import { EventData, WebView } from '#nativescript/core';
.
.
.
onLoadFinished(event: EventData) {
const webView = <WebView>event.object;
webView.style.height = 0;
setTimeout(() => {
webView.style.height = 'auto';
}, 100);
}
You can put your webview in a GridLayout that has rows=*, columns=* to resolve the height by the grid layout.
<GridLayout columns="*" rows="*">
<WebView row="0" col="0" id="wv" height="100%"/>
</GridLayout>
I have a widget.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widget"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
style="#style/WidgetBackground">
<ImageView
android:id="#+id/myimage"
android:layout_width="20dip"
android:layout_height="20dip"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/myimage" />
<TextView
android:id="#+id/mytext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/WidgetText.Title" />
How can I change the size of the image?
[Service]
public class UpdateService : Service
{
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
{
var updateViews = new RemoteViews(context.PackageName, Resource.Layout.widget);
// changing textsize works perfectly:
updateViews.SetTextViewTextSize(Resource.Id.mytext, (int)ComplexUnitType.Sp, 14);
updateViews.SetViewVisibility(Resource.Id.myimage, ViewStates.Gone);
updateViews.SetTextViewText(Resource.Id.text, "new text");
// but changing imagesize does not work, I didn't find a right way to set the size, need something like this:
updateViews.SetInt(Resource.Id.myimage, "layout_width ???", 200dip ???);
ComponentName thisWidget = new ComponentName(this, Java.Lang.Class.FromType(typeof(Widget)).Name);
AppWidgetManager manager = AppWidgetManager.GetInstance(this);
manager.UpdateAppWidget(thisWidget, updateViews);
}
updateViews has several setInt, setFloat, Set.. but I didn't find the right method. Any hint please?
It's impossible to change the height or width of the ImageView in code, but there is some workaround.
You could try to create a new widget layout that the size of your ImageView is what you want. When you call RemoteViews() use it instead of the original one. And when you update the widget, it will be redrawn.
For example:
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
{
//var updateViews = new RemoteViews(this.PackageName, Resource.Layout.widget);
//Using another layout instead.
var updateViews = new RemoteViews(this.PackageName, Resource.Layout.layout1);
ComponentName thisWidget = new ComponentName(this, Java.Lang.Class.FromType(typeof(MyWidget)).Name);
AppWidgetManager manager = AppWidgetManager.GetInstance(this);
manager.UpdateAppWidget(thisWidget, updateViews);
///...
///...
}
Or you could also try to add manyImageView of different size in your layout and set the Visibility to Gone. Show the one you want to display in the code by calling SetViewVisibility().
You can try this method:
var videoContainer = FindViewById<RelativeLayout>(Resource.Id.local_video_container);
var parameters = videoContainer.LayoutParameters;
parameters.Height = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, containerHeight, Resources.DisplayMetrics);
parameters.Width = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, containerWidth, Resources.DisplayMetrics);
videoContainer.LayoutParameters = parameters;
I'm trying to solve problem:
TimeChartView should be scrolled (navigate) to specific X axis value after app startup.
I'm trying to use ChartView.scrollTo (X, 0) and mChartView.setX(X)
But it works not like it was to be expected.
It's looks like ChartView moved by itself in layout instead of scroll.
Where is my mistake? Any other more suitable solution for this case?
Here is my code:
1) layout
<ScrollView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:fillViewport="true"
android:background="#000000"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:layout_gravity="bottom"
android:gravity="bottom"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/chartx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFAA00" <---------- ORANGE PART OF SCREEN, u can see on screenshot
android:gravity="bottom"
android:orientation="horizontal"
android:scrollbars="horizontal" >
</LinearLayout>
</LinearLayout>
</ScrollView>
2) activity
lChart = (LinearLayout) mapV.findViewById(R.id.chartx);
if (mChartView != null) {
lChart.removeView(mChartView);
}
mChartView = ChartFactory.getTimeChartView(mapActivity, mDataset, mRenderer, "dd/MMM/yy");
mChartView.scrollTo(100, 0);
lChart.addView(mChartView, 0, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
mChartView.repaint();
3) Data
for (int i = 0; i < 90; i++) {
c.set(c.MILLISECOND, 0);
c.set(c.SECOND, 0);
c.set(c.MINUTE, 0);
c.set(c.HOUR, 0);
time_series.add(new Date(value + i*cTimeChart.DAY), 0);
}
Let's say we are adding 90 values but we want our scrollable ChartView will be opened (visible) on value 45.
That's what I want to get to.
Here my screenshot
https://dl.dropboxusercontent.com/u/42675740/Screenshot.png
background="#FFAA00" - Orange part of screen, looks like ChartView moved inside layout.
And what I'm expecting - dates should be scrolled instead of view moving.
BTW. I'm using achartengine-1.1.0
The YouTube Player will play videos no problem either without the transparent panel on the form or it will play them in full screen, the transparent panel has some images in it nothing special. If I take out the transparent panel, the YouTube Player works as desired, embedded in app. If I add the transparent panel to the form, this is when it will not play but in full screen. The video starts and then stops instantly. I assume it has something to do with the transparent panel but I can not understand what is happening. Any help or thoughts would be great. My java file does not change except for the initPopup would not be there. Shortened Java file version below.
XML Layout File Below:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mlayout"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<com.google.android.youtube.player.YouTubePlayerView
android:id="#+id/youtube_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/spnrPSA" >
</com.google.android.youtube.player.YouTubePlayerView>
</RelativeLayout>
<com.TransparentPanel
android:id="#+id/popup_window"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:gravity="left"
android:orientation="vertical"
android:padding="1px" >
<com.TransparentPanel>
</RelativeLayout>
JAVA File Below:
public final class PSA extends YouTubeFailureRecoveryActivity{
private Animation animShow, animHide;
private YouTubePlayer player;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.psa);
initPopup();
}
private void initPopup() {
final TransparentPanel popup = (TransparentPanel) findViewById(R.id.popup_window);
// Start out with the popup initially hidden.
popup.setVisibility(View.GONE);
if (PubVars.ScreenOrientation==0){
animShow = AnimationUtils.loadAnimation( this, R.anim.popup_show);
animHide = AnimationUtils.loadAnimation( this, R.anim.popup_hide);
}
if (PubVars.ScreenOrientation==1){
animShow = AnimationUtils.loadAnimation( this, R.anim.l_popup_show);
animHide = AnimationUtils.loadAnimation( this, R.anim.l_popup_hide);
}
//animShow = AnimationUtils.loadAnimation( this, R.anim.popup_show);
//animHide = AnimationUtils.loadAnimation( this, R.anim.popup_hide);
final ImageView showButton = (ImageView) findViewById(R.id.show_popup_button);
final ImageView hideButton = (ImageView) findViewById(R.id.hide_popup_button);
showButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
popup.setVisibility(View.VISIBLE);
popup.startAnimation( animShow );
showButton.setEnabled(false);
hideButton.setEnabled(true);
}});
hideButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
popup.startAnimation( animHide );
showButton.setEnabled(true);
hideButton.setEnabled(false);
popup.setVisibility(View.GONE);
}});
}
}
I must be missing something simple. Thanks in advance, I am fairly new to android.
Youtube Player View does not authorize overlays. Even if it's a transparent Layout(Relative, frame, ..).
The player stops the video and log into logcat some useful info. But this case is reported as "youtubeplayer is completely covered".
This api not permit anyone layer over this. "Layout is the problem"
I suggest you use the hierarchy View to see this on your layout.
I have many problems with it, because my layout stay over a little point over player.
I am trying to create a table view with a text view and a button in android. Below is my sample code ( work in progress ). As I am very new to android please help me how to arrange the text view and the button as in the image. Now I am getting button and text view. But its weird.
My Code
TableLayout table = (TableLayout)findViewById(R.id.tableLayout_1);
for (int i = 0; i<30; i++)
{
TableRow row = new TableRow(this);
row.setBackgroundColor(Color.DKGRAY);
TextView tv = new TextView(this);
Button btn=new Button(this);
tv.setTextAppearance(getApplicationContext(), R.style.maxWid);
tv.setText("Sample Text Here");
row.addView(tv);
btn.setText("Approves");
row.addView(btn);
table.addView(row);
}
Style.xml
<style name="maxWid">
<item name="android:textStyle">bold|italic</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:layout_width">fill_parent</item>
</style>
main_layout.xml
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:layout_weight="1">
<TableLayout
android:id="#+id/tableLayout_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="*"
android:stretchColumns="*"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
</TableLayout>
</ScrollView>
Expected format
Fighting with this since 1 day.. Please help
Thanks in advance!
what you can do here is create a layout xml using RelativeLayout and then add that into your TableRow.