2016-05-07 56 views
2

我做臥式畫廊應用程序然後我按任何圖像,我去網站,但是當按下接近頁面時,網站是垂直的,並且在網站的主要畫廊不是水平的。 通知:應用程序強制在所有活動的景觀在風景中保持webview

我怎麼能保持webview在景觀? 或者我該如何解決它?

這是網站,我就可以工作,這裏的時候,我按x圖像,問題開始http://shoppinz.com/#&gallery=627

package ikh.ago.com.mall; 
 

 
import android.app.Activity; 
 
import android.support.v7.app.AppCompatActivity; 
 
import android.os.Bundle; 
 
import android.webkit.WebView; 
 
import android.webkit.WebViewClient; 
 
import android.widget.Toast; 
 

 
public class Zara_Women extends AppCompatActivity { 
 

 
    private WebView news ; 
 
    @Override 
 

 
    public void onCreate (Bundle savedInstanceState) { 
 

 
     super.onCreate(savedInstanceState); 
 
     news = new WebView (this); 
 
     news.getSettings().setJavaScriptEnabled(true); 
 
     final Activity activity = this; 
 

 
     news.setWebViewClient(new WebViewClient(){ 
 
      public void onReceivedError (WebView view , int errorCode , String description , String failingURI){ 
 
       Toast.makeText(activity, description, Toast.LENGTH_SHORT).show(); 
 
      } 
 
     }); 
 

 
     news.loadUrl("http://shoppinz.com/#&gallery=627"); 
 
     setContentView(news) ; 
 

 
    } 
 

 
}
<?xml version="1.0" encoding="utf-8"?> 
 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 
    xmlns:tools="http://schemas.android.com/tools" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent" 
 
    android:paddingBottom="@dimen/activity_vertical_margin" 
 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
 
    android:paddingRight="@dimen/activity_horizontal_margin" 
 
    android:paddingTop="@dimen/activity_vertical_margin" 
 
    tools:context="ikh.ago.com.mall.Zara_Women"> 
 

 
    <WebView 
 
     android:layout_width="match_parent" 
 
     android:layout_height="match_parent" 
 
     android:id="@+id/news" 
 
     android:layout_alignParentTop="true" 
 
     android:layout_centerHorizontal="true" /> 
 

 
</RelativeLayout>
package ikh.ago.com.mall; 
 

 
import android.content.Context; 
 
import android.content.Intent; 
 
import android.net.ConnectivityManager; 
 
import android.net.NetworkInfo; 
 
import android.os.Bundle; 
 
import android.support.design.widget.FloatingActionButton; 
 
import android.support.design.widget.NavigationView; 
 
import android.support.design.widget.Snackbar; 
 
import android.support.v4.view.GravityCompat; 
 
import android.support.v4.widget.DrawerLayout; 
 
import android.support.v7.app.ActionBarDrawerToggle; 
 
import android.support.v7.app.AppCompatActivity; 
 
import android.support.v7.widget.Toolbar; 
 
import android.view.Menu; 
 
import android.view.MenuItem; 
 
import android.view.View; 
 
import android.widget.ImageView; 
 
import android.widget.Toast; 
 

 
public class MainActivity extends AppCompatActivity 
 
     implements NavigationView.OnNavigationItemSelectedListener { 
 

 
    @Override 
 
    protected void onCreate(Bundle savedInstanceState) { 
 
     super.onCreate(savedInstanceState); 
 
     setContentView(R.layout.activity_main); 
 
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
 
     setSupportActionBar(toolbar); 
 

 

 
     ConnectivityManager cm = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE); 
 
     NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); 
 

 

 
     if (null != activeNetwork) { 
 
      if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI || activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) { 
 
       //answer = "You are connected to network"; 
 
       //Toast.makeText(getApplicationContext(), answer, Toast.LENGTH_LONG).show(); 
 

 
       ImageView zarawomen = (ImageView) findViewById(R.id.zarawomen) ; 
 
       zarawomen.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Intent n1 = new Intent(MainActivity.this, Zara_Women.class); 
 
         startActivity(n1); 
 
        } 
 
       }); 
 

 
       ImageView massemo_women = (ImageView) findViewById(R.id.massimoduttiwomen) ; 
 
       massemo_women.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Intent n1 = new Intent(MainActivity.this, Massemo_Women.class); 
 
         startActivity(n1); 
 
        } 
 
       }); 
 

 

 
       ImageView mango = (ImageView) findViewById(R.id.mango) ; 
 
       mango.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Intent n1 = new Intent(MainActivity.this, Mango.class); 
 
         startActivity(n1); 
 
        } 
 
       }); 
 

 

 
       ImageView pbstore = (ImageView) findViewById(R.id.pbstore) ; 
 
       pbstore.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Intent n1 = new Intent(MainActivity.this, Pull_Bear_Women.class); 
 
         startActivity(n1); 
 
        } 
 
       }); 
 

 

 

 
       ImageView bershka2 = (ImageView) findViewById(R.id.bershka2) ; 
 
       bershka2.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Intent n1 = new Intent(MainActivity.this, Breshka.class); 
 
         startActivity(n1); 
 
        } 
 
       }); 
 

 

 
       ImageView gap = (ImageView) findViewById(R.id.gap) ; 
 
       gap.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Intent n1 = new Intent(MainActivity.this, Gap.class); 
 
         startActivity(n1); 
 
        } 
 
       }); 
 

 

 
       ImageView massemo_men = (ImageView) findViewById(R.id.massimoduttimen) ; 
 
       massemo_men.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Intent n1 = new Intent(MainActivity.this, Massemo_Men.class); 
 
         startActivity(n1); 
 
        } 
 
       }); 
 

 

 
       ImageView pb = (ImageView) findViewById(R.id.pb) ; 
 
       pb.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Intent n1 = new Intent(MainActivity.this, Pull_Bear_Men.class); 
 
         startActivity(n1); 
 
        } 
 
       }); 
 

 
       ImageView zaraman = (ImageView) findViewById(R.id.zaraman) ; 
 
       zaraman.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Intent n1 = new Intent(MainActivity.this, Zara_Men.class); 
 
         startActivity(n1); 
 
        } 
 
       }); 
 

 
       ImageView cafehello = (ImageView) findViewById(R.id.cafehello) ; 
 
       cafehello.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Intent n1 = new Intent(MainActivity.this, Cafe_Hello.class); 
 
         startActivity(n1); 
 
        } 
 
       }); 
 

 
       ImageView costa = (ImageView) findViewById(R.id.costa) ; 
 
       costa.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Intent n1 = new Intent(MainActivity.this, Costa.class); 
 
         startActivity(n1); 
 
        } 
 
       }); 
 

 
       ImageView compume = (ImageView) findViewById(R.id.compume) ; 
 
       compume.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Intent n1 = new Intent(MainActivity.this, Compume.class); 
 
         startActivity(n1); 
 
        } 
 
       }); 
 

 
       ImageView englander = (ImageView) findViewById(R.id.englander) ; 
 
       englander.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Intent n1 = new Intent(MainActivity.this, Englander.class); 
 
         startActivity(n1); 
 
        } 
 
       }); 
 

 
       ImageView casio = (ImageView) findViewById(R.id.casio) ; 
 
       casio.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Intent n1 = new Intent(MainActivity.this, Casio.class); 
 
         startActivity(n1); 
 
        } 
 
       }); 
 

 

 
      } else { 
 
       //answer = "No Network Connectivity"; 
 
       //Toast.makeText(getApplicationContext(), answer, Toast.LENGTH_LONG).show(); 
 
       ImageView zarawomen = (ImageView) findViewById(R.id.zarawomen) ; 
 
       zarawomen.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Toast.makeText(MainActivity.this, "No network connectivity", Toast.LENGTH_SHORT).show(); 
 
        } 
 
       }); 
 

 

 
       ImageView massemo_women = (ImageView) findViewById(R.id.massimoduttiwomen) ; 
 
       massemo_women.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Toast.makeText(MainActivity.this, "No network connectivity", Toast.LENGTH_SHORT).show(); 
 
        } 
 
       }); 
 

 

 
       ImageView mango = (ImageView) findViewById(R.id.mango) ; 
 
       mango.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Toast.makeText(MainActivity.this, "No network connectivity", Toast.LENGTH_SHORT).show(); 
 
        } 
 
       }); 
 

 

 
       ImageView pbstore = (ImageView) findViewById(R.id.pbstore) ; 
 
       pbstore.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Toast.makeText(MainActivity.this, "No network connectivity", Toast.LENGTH_SHORT).show(); 
 
        } 
 
       }); 
 

 

 
       ImageView bershka2 = (ImageView) findViewById(R.id.bershka2) ; 
 
       bershka2.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Toast.makeText(MainActivity.this, "No network connectivity", Toast.LENGTH_SHORT).show(); 
 
        } 
 
       }); 
 

 

 
       ImageView gap = (ImageView) findViewById(R.id.gap) ; 
 
       gap.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Toast.makeText(MainActivity.this, "No network connectivity", Toast.LENGTH_SHORT).show(); 
 
        } 
 
       }); 
 

 

 
       ImageView massemo_men = (ImageView) findViewById(R.id.massimoduttimen) ; 
 
       massemo_men.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Toast.makeText(MainActivity.this, "No network connectivity", Toast.LENGTH_SHORT).show(); 
 
        } 
 
       }); 
 

 

 
       ImageView pb = (ImageView) findViewById(R.id.pb) ; 
 
       pb.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Toast.makeText(MainActivity.this, "No network connectivity", Toast.LENGTH_SHORT).show(); 
 
        } 
 
       }); 
 

 
       ImageView zaraman = (ImageView) findViewById(R.id.zaraman) ; 
 
       zaraman.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Toast.makeText(MainActivity.this, "No network connectivity", Toast.LENGTH_SHORT).show(); 
 
        } 
 
       }); 
 

 
       ImageView cafehello = (ImageView) findViewById(R.id.cafehello) ; 
 
       cafehello.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Toast.makeText(MainActivity.this, "No network connectivity", Toast.LENGTH_SHORT).show(); 
 
        } 
 
       }); 
 

 
       ImageView costa = (ImageView) findViewById(R.id.costa) ; 
 
       costa.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Toast.makeText(MainActivity.this, "No network connectivity", Toast.LENGTH_SHORT).show(); 
 
        } 
 
       }); 
 

 
       ImageView compume = (ImageView) findViewById(R.id.compume) ; 
 
       compume.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Toast.makeText(MainActivity.this, "No network connectivity", Toast.LENGTH_SHORT).show(); 
 
        } 
 
       }); 
 

 
       ImageView englander = (ImageView) findViewById(R.id.englander) ; 
 
       englander.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Toast.makeText(MainActivity.this, "No network connectivity", Toast.LENGTH_SHORT).show(); 
 
        } 
 
       }); 
 

 
       ImageView casio = (ImageView) findViewById(R.id.casio) ; 
 
       casio.setOnClickListener(new View.OnClickListener() { 
 
        @Override 
 
        public void onClick(View v) { 
 
         Toast.makeText(MainActivity.this, "No network connectivity", Toast.LENGTH_SHORT).show(); 
 
        } 
 
       }); 
 

 
      } 
 
    } 
 

 
     FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 
 
     fab.setOnClickListener(new View.OnClickListener() { 
 
      @Override 
 
      public void onClick(View view) { 
 
       Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 
 
         .setAction("Action", null).show(); 
 
      } 
 
     }); 
 

 
     DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
 
     ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
 
       this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 
 
     drawer.setDrawerListener(toggle); 
 
     toggle.syncState(); 
 

 
     NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 
 
     navigationView.setNavigationItemSelectedListener(this); 
 

 

 
    } 
 

 

 

 

 
    @Override 
 
    public void onBackPressed() { 
 
     DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
 
     if (drawer.isDrawerOpen(GravityCompat.START)) { 
 
      drawer.closeDrawer(GravityCompat.START); 
 
     } else { 
 
      super.onBackPressed(); 
 
     } 
 
    } 
 

 
    @Override 
 
    public boolean onCreateOptionsMenu(Menu menu) { 
 
     // Inflate the menu; this adds items to the action bar if it is present. 
 
     getMenuInflater().inflate(R.menu.main, menu); 
 
     return true; 
 
    } 
 

 
    @Override 
 
    public boolean onOptionsItemSelected(MenuItem item) { 
 
     // Handle action bar item clicks here. The action bar will 
 
     // automatically handle clicks on the Home/Up button, so long 
 
     // as you specify a parent activity in AndroidManifest.xml. 
 
     int id = item.getItemId(); 
 

 
     //noinspection SimplifiableIfStatement 
 
     if (id == R.id.action_settings) { 
 
      return true; 
 
     } 
 

 
     return super.onOptionsItemSelected(item); 
 
    } 
 

 
    @SuppressWarnings("StatementWithEmptyBody") 
 
    @Override 
 
    public boolean onNavigationItemSelected(MenuItem item) { 
 
     // Handle navigation view item clicks here. 
 
     int id = item.getItemId(); 
 

 
     if (id == R.id.nav_zarawomen) { 
 
      Intent intent = new Intent(this, Zara_Women.class); 
 
      this.startActivity(intent); 
 
     } else if (id == R.id.nav_massemowomen) { 
 
      Intent intent = new Intent(this, Massemo_Women.class); 
 
      this.startActivity(intent); 
 
     } else if (id == R.id.nav_mango) { 
 
      Intent intent = new Intent(this, Mango.class); 
 
      this.startActivity(intent); 
 
     } else if (id == R.id.nav_pullwomen) { 
 
      Intent intent = new Intent(this, Pull_Bear_Women.class); 
 
      this.startActivity(intent); 
 
     } else if (id == R.id.nav_bershka) { 
 
      Intent intent = new Intent(this, Breshka.class); 
 
      this.startActivity(intent); 
 
     } else if (id == R.id.nav_gap) { 
 
      Intent intent = new Intent(this, Gap.class); 
 
      this.startActivity(intent); 
 
     } else if (id == R.id.nav_massemomen) { 
 
      Intent intent = new Intent(this, Massemo_Men.class); 
 
      this.startActivity(intent); 
 
     } else if (id == R.id.nav_pullmen) { 
 
      Intent intent = new Intent(this, Pull_Bear_Men.class); 
 
      this.startActivity(intent); 
 
     } else if (id == R.id.nav_zaramen) { 
 
      Intent intent = new Intent(this, Zara_Men.class); 
 
      this.startActivity(intent); 
 
     } else if (id == R.id.nav_hellocafe) { 
 
      Intent intent = new Intent(this, Cafe_Hello.class); 
 
      this.startActivity(intent); 
 
     } else if (id == R.id.nav_costa) { 
 
      Intent intent = new Intent(this, Costa.class); 
 
      this.startActivity(intent); 
 
     } else if (id == R.id.nav_compume) { 
 
      Intent intent = new Intent(this, Compume.class); 
 
      this.startActivity(intent); 
 
     } else if (id == R.id.nav_englander) { 
 
      Intent intent = new Intent(this, Englander.class); 
 
      this.startActivity(intent); 
 
     } else if (id == R.id.nav_casio) { 
 
      Intent intent = new Intent(this, Casio.class); 
 
      this.startActivity(intent); 
 
     } 
 

 

 
     DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
 
     drawer.closeDrawer(GravityCompat.START); 
 
     return true; 
 
    } 
 
}

回答

0

你可以在按鈕使用此ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE單擊啓動中的WebView景觀。

在你Zara_Women

@Override 
public void onCreate (Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 
    news = new WebView (this); 
    news.getSettings().setJavaScriptEnabled(true); 
    final Activity activity = this; 

    news.setWebViewClient(new WebViewClient(){ 
     public void onReceivedError (WebView view , int errorCode , String description , String failingURI){ 
      Toast.makeText(activity, description, Toast.LENGTH_SHORT).show(); 
     } 
    }); 

    news.loadUrl("http://shoppinz.com/#&gallery=627"); 
     setContentView(news) ; 

} 
+0

首先,感謝幫助我,我是你更改後的測試代碼,屏幕已經是景觀,但網頁流量後,按接近垂直。我能做什麼 ? –

+0

請解釋你按下關閉按鈕的位置? – Max

+0

我想要webview的內容是水平的 –