Add two webview in layout and get event click to webview - android

I want to create an app with UI as follow..I have two webview add in screen..I want to when click to webview2,webview1 will hide and webview2 will fill fullscreen...If two webview load url is "http://www.google.com" ,it will display two webview separate but if I load an url different "http://www.google.com" as "http://www.youtube.com" it only display 1 webview youtube full screen..How I must do..Thank
Here is file XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/layout1"
android:layout_weight="1"
>
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/webview1"
/>
</LinearLayout>
<LinearLayout
android:layout_weight="4"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/layout2"
android:layout_marginLeft="10dip"
>
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/webview2"
/>
</LinearLayout>
and here is code in Activity:
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
height = displaymetrics.heightPixels;
width = displaymetrics.widthPixels;
layout1=(LinearLayout)findViewById(R.id.layout1);
layout2=(LinearLayout)findViewById(R.id.layout2);
webview1=(WebView)findViewById(R.id.webview1);
webview1.loadUrl("http://www.google.com");
webview2=(WebView)findViewById(R.id.webview2);
webview2.loadUrl("http://www.google.com");
final LayoutParams lp=webview1.getLayoutParams();
final LayoutParams lp1=webview2.getLayoutParams();
lp.height=height;
lp1.height=height;
webview1.setLayoutParams(lp);
webview2.setLayoutParams(lp1);
webview2.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
webview1.setVisibility(View.GONE);
lp.height=height;
lp.width=width;
webview2.setLayoutParams(lp);
}
});

I would recommend creating 2 custom WebViews.
WebView wv1 = findViewById(ID_WEBVIEW_1);
WebView wv2 = findViewById(ID_WEBVIEW_2);
if (wv1.getUrl() != "http://google.com" || wv2.getUrl() != "http://google.com") {
((ViewManager)entry.getParent()).removeView(entry);
}
http://developer.android.com/reference/android/view/ViewManager.html

Related

Android page numbring displayed at the bottom bar

I want to display a page numbering, like 3/10 at the bottom of my app, after swiping, the number will be 4/10.
My layout is webviews that the user ban swipe between them, i want to indicate the webview current index in a bottom bar that will be updated after each swipe.
basic layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px">
<android.webkit.WebView
android:layout_width="match_parent"
android:layout_height="413.3dp"
android:id="#+id/tipsWebView"
android:layout_marginBottom="0.0dp" />
//bar position
</LinearLayout>
And to display different webviews i use :
adaptor.AddFragmentView((i, v, b) =>
{
if(m_swipeCounter < m_links.Length)
{
m_swipeCounter++;
}
else
{
m_swipeCounter= 0;
}
var view = i.Inflate(Resource.Layout.tab, v, false);
var client = new WebClient();
string htmlData = client.DownloadString(m_links[m_swipeCounter]);
htmlData +="<link rel=\"stylesheet\" type=\"text/css\" href=\"cssInject.css\">";
WebView tipsWebView = view.FindViewById<WebView>(Resource.Id.tipsWebView);
tipsWebView.SetWebViewClient(new WebViewClient());
tipsWebView.Settings.JavaScriptEnabled = true;
tipsWebView.LoadDataWithBaseURL("file:///android_asset/", htmlData, "text/html", "", null);
return view;
//create pager, pager adaptor to create the right webview link
});
So the index will be based on m_swipeCounter variable.
All the best.
it's possible with a LinearLayout, using weights and stuff, but it'll run faster using a RelativeLayout
<?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"
>
<android.webkit.WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/tipsWebView"
android:layout_alignParentTop="true"
android:layout_above="#+id/bottomText"
/>
<TextView
android:id="#+id/bottomText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="0/0"
/>
</RelativeLayout>

ScrollView doesn't want to show up with Image

I'm wondering all the time why the scrollView dosen't want to show up. I'm downloading some image from the Internet and then setting it as a Drawable in a ImageView but nothing happens. When picture is small everything works fine. Where is the mistake?
Funkction where I'm populating View:
public void setUpLayout()
{
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;
heightOfScreen = height;
heighOfImage = image.getHeight();
System.out.println("Screen" +height);
System.out.println("IMAGE" + heighOfImage);
if(heighOfImage < height)
{
imageViewSmall.setImageBitmap(image);
imageViewSmall.setVisibility(View.VISIBLE);
scrollViewImage.setEnabled(false);
}
else
{
scrollViewImage.setVisibility(View.VISIBLE);
imageViewBig.setImageBitmap(image);
//imageViewBig.setVisibility(View.VISIBLE);
scrollViewImage.setEnabled(false);
}
}
And XML file with all content View:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gesture-image="http://schemas.polites.com/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_height="20dp"
android:layout_width="fill_parent"
android:id="#+id/textB"
android:text="dadasadsadsasddassdsdsdsadasdd"/>
<com.polites.android.GestureImageView
android:id="#+id/imageSmal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below ="#+id/textB"
android:visibility="gone"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
gesture-image:max-scale="10.0"
gesture-image:min-scale="0.0"
gesture-image:strict="false" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/imageSmal"
android:id="#+id/scrollViewImage"
android:scrollbars="none"
android:visibility="gone">
<com.polites.android.GestureImageView
android:id="#+id/imageBig"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
gesture-image:max-scale="10.0"
gesture-image:min-scale="0.0"
gesture-image:strict="false" />
</ScrollView>
<ProgressBar
android:id="#+id/imageProgressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
</RelativeLayout>

Tap preview thumbnail to view high resolution image

I am a new android developer and I am trying to create an android app for android in which menu items will be displayed along with description cost and image.
I have implemented List activity to display the items in a list. I made an image Button which will show the image in a thumbnail. I want to be able to view a high resolution image of the thumbnail when I tap on the image button. I have implemented an onClickListener to listen to the tap event but I do not know the methods that will make the image zoom out on tap.
I have followed this link
but it is quite ambiguous to understand. The Animator class doesn't exist. Can someone guide me out o fthis?
I found the solution after searching for almost a week.
I used PopupWindow Class for the purpose
Following is the Java Code.
PopupWin.java
public class PopupWin extends Activity{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button bPopup = (Button)findViewById(R.id.openpopup);
bPopup.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View arg0) {
LayoutInflater layoutInflater
= (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
Button bDismiss = (Button)popupView.findViewById(R.id.dismiss);
bDismiss.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}});
popupWindow.showAsDropDown(bPopup, 50, -30);
}});
}
}
popup.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pop"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/dim_back" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/dim_back"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:orientation="vertical"
android:layout_gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:adjustViewBounds="true"
android:src="#drawable/appetimg01" />
<Button
android:id="#+id/dismiss"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20sp"
android:text="Go Back"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/appetizerDes1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="0.40"
android:text="Tap the Image to view High Resolution Image."/>
<Button
android:id="#+id/openpopup"
android:layout_width="80sp"
android:layout_height="80sp"
android:layout_gravity="right"
android:layout_margin="40sp"
android:background="#drawable/custombutton"
android:scaleType="centerCrop" />
</LinearLayout>
</LinearLayout>
The background was appearing white but I wanted it transparent for which I created back_dim.xml in drawables and set it along with android:background="#drawable/back_dim".

How can i write this layout code in my Android Activity?

I wish to create a custom layout out for my sample application. Previously i used the xml layout for User interface, but now i wish to create the application using custom (without using xml layout). I used the below code in my xml, but i change this xml layout to custom code i can't implement (i don't have knowledge how to do this). How can i write this layout code in my Activity?. Any one could you please help me to solve this. Thanks in advance.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/webviewscroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/webviewlinear"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/webviewframe1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<WebView
android:id="#+id/webview1"
android:layout_width="fill_parent"
android:layout_height="350dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp" >
</WebView>
<ImageView
android:id="#+id/webviewimage1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/one" >
</ImageView>
</RelativeLayout>
<RelativeLayout
android:id="#+id/webviewframe2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<WebView
android:id="#+id/webview2"
android:layout_width="fill_parent"
android:layout_height="350dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp" >
</WebView>
<ImageView
android:id="#+id/webviewimage2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/two" >
</ImageView>
</RelativeLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
As you want to create layout at run-time, you can do this way:
RelativeLayout layout1 = new RelativeLayout(this);
ImageView imgView1 = new imgView1(this);
layout1.addView(imgView1); // added ImageView into the RelativeLayout
do this kind of process for creating and adding widgets.
LinearLayout ll1,ll2;
ScrollView sv = new ScrollView(this);
RelativeLayout rl1,rl2;
WebView wv1,wv2;
ImageView iv1,iv2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int LHeightWrap = LinearLayout.LayoutParams.WRAP_CONTENT;
int LWidthWrap = LinearLayout.LayoutParams.WRAP_CONTENT;
int LHeightFill = LinearLayout.LayoutParams.FILL_PARENT;
int LWidthFill = LinearLayout.LayoutParams.FILL_PARENT;
int RHeightWrap = RelativeLayout.LayoutParams.WRAP_CONTENT;
int RWidthWrap = RelativeLayout.LayoutParams.WRAP_CONTENT;
int RHeightFill = RelativeLayout.LayoutParams.FILL_PARENT;
int RWidthFill = RelativeLayout.LayoutParams.FILL_PARENT;
wv1 = new WebView(this);
iv1 = new ImageView(this);
rl1.addView(wv1,RWidthWrap,RHeightWrap);
rl1.addView(iv1,RWidthWrap,RHeightWrap);
wv2 = new WebView(this);
iv2 = new ImageView(this);
rl2.addView(wv2,RWidthWrap,RHeightWrap);
rl2.addView(iv2,RWidthWrap,RHeightWrap);
ll2.addView(rl1);
ll2.addView(rl2);
sv.addView(ll2);
ll1.addView(ll2);
You can do somthing like this. You can also set properties of any component using native code.

Issue with webview and scrollview

I can't resolve my problem with scrollView and webView,
I know, that i can't put webview into scrollview but I have't idea how to jump it.
In my scrollView, I have image ( 1280 x 1300 > ) and this image must be scrolling, under image i must have webview with html content. have you any idea how should I do that?
is any another way to put html content with to some view?
this is my xml view, and I add image and webview in my activity class
<?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:id="#+id/mainLinear"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:id="#+id/scroll_journal_page"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ScrollView>
<Gallery
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#d5d5d3" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
i create view somethink like that:
protected void onPostExecute(Bitmap result) {
Animation fadeInAnimation = AnimationUtils.loadAnimation(Journal.this, R.anim.fade_in);
relativeLayout = new LinearLayout(getApplicationContext());
relativeLayout.setLayoutParams(new FrameLayout.LayoutParams(WIDTH, result.getHeight() + HEIGHT));
relativeLayout.setOrientation(1);
coverImage = new ImageView(getApplicationContext());
coverImage.setImageBitmap(result);
relativeLayout.addView(coverImage);
Integer pageNumber = Integer.valueOf(ArrayHelper.journalList.get(pageIdentity).get("pageId").toString());
File file = new File(Environment.getExternalStorageDirectory() + "/MCW/"+ pageNumber +"/content.html");
if(file.exists()) {
LinearLayout linearLayout = new LinearLayout(getApplicationContext());
linearLayout.setLayoutParams(new FrameLayout.LayoutParams(WIDTH, HEIGHT));
WebView wV = new WebView(getApplicationContext());
try {
InputStream fin = null;
int len;
fin = new BufferedInputStream(new FileInputStream(file));
byte[] buffer = new byte[fin.available()];
len = fin.read(buffer);
fin.close();
String rawText = EncodingUtils.getString(buffer, 0, len, "utf-8");
wV.loadDataWithBaseURL("", rawText, "text/html", "utf-8", null);
}catch (Exception e) {}
linearLayout.addView(wV);
relativeLayout.addView(linearLayout);
}
scrollview.addView(relativeLayout);
scrollview.setAnimation(fadeInAnimation);
isReadyToChange = true;
}
Just use a Scrollview with Height FillParent
add a linearlayout height= deviceHeight+imageHeight
use a linearlayout with height of device
add webview to this linearlayout
add image and linearlayout to this layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView android:layout_width="wrap_content"
android:layout_height="fill_parent">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView android:id="#+id/pho"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/dd1"/>
<WebView android:id="#+id/webView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
I am not sure whether this would meet your requirement or not, however
is any another way to put html content with to some view ?
You can use TextView to display HTML content
mTextView.setText(Html.fromHtml('html_content'));
Also go through Mark Murphy - HTML Tags Supported By TextView
As a side note, HTML may also be used as a string resource, as described Here

Categories

Resources