title: LinearLayout larger than screen
body: <p>I am trying to create a horizontal <code>LinearLayout</code> which is wider than the screen of the device. It contains a <code>Button</code> which will move the layout to view the part outside the screen when it is clicked. The problem is that android is not creating the part outside the screen, so when I press the button, the view moves to show black screen where the remaining view should have been.</p>
  
  <p>My code-</p>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>public class MainActivity extends BaseGameActivity implements OnClickListener {
  
      private Context mContext;
      private int mScreenHeight;
      private int mScreenWidth;
      private LinearLayout mViewContainer;
      private View mTransparentContainer;
      private Button mSliderBtn;
      private View mSlidingView;
      private View mHomeView;
      private int mSlidingWidth;
      private boolean mIsSlidingMenuVisible = false;
  
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          mContext = getApplicationContext();
          mScreenHeight = UserScreen.getHeight(mContext);
          mScreenWidth = UserScreen.getWidth(mContext);
          mSlidingWidth = (int) (getResources().getDimension(R.dimen.sliding_menu_offset) + 0.5f);
  
          mViewContainer = new LinearLayout(mContext);
          mViewContainer.setOrientation(LinearLayout.HORIZONTAL);
          mViewContainer.setLayoutParams(new LinearLayout.LayoutParams(mScreenWidth + mSlidingWidth, mScreenHeight));
          setContentView(mViewContainer);
  
          LinearLayout homeContainer = new LinearLayout(mContext);
          LinearLayout.LayoutParams homeContainerParams = new LinearLayout.LayoutParams(mScreenWidth, LayoutParams.MATCH_PARENT);
          mHomeView = getLayoutInflater().inflate(R.layout.activity_main, homeContainer);
          mHomeView.setBackgroundColor(0x80ffffff);
          mViewContainer.addView(homeContainer, homeContainerParams);
  
          LinearLayout slidingContainer = new LinearLayout(mContext);
          LinearLayout.LayoutParams slidingContainerParams = new LinearLayout.LayoutParams(mSlidingWidth, LayoutParams.MATCH_PARENT);
          mSlidingView = getLayoutInflater().inflate(R.layout.slider_menu, slidingContainer);
          mViewContainer.addView(slidingContainer, slidingContainerParams);
  
          initUi();
  
          // other code
      }
  
      public void initUi() {
          mSliderBtn = (Button) mHomeView.findViewById(R.id.button_slider);
          mSliderBtn.setOnClickListener(this);
  
          mTransparentContainer = mHomeView.findViewById(R.id.transparent_container);
          mTransparentContainer.setOnClickListener(this);
  
          // other code
      }
  
      @Override
      public void onClick(View view) {
          switch (view.getId()) {
          case R.id.button_slider:
              mSliderBtn.setEnabled(false);
              mIsSlidingMenuVisible = true;
              mTransparentContainer.setVisibility(View.VISIBLE);
              mTransparentContainer.bringToFront();
              tableMoveLeft(mViewContainer, mSlidingWidth);
              break;
          case R.id.transparent_container:
              mSliderBtn.setEnabled(true);
              mIsSlidingMenuVisible = false;
              mTransparentContainer.setVisibility(View.GONE);
              tableMoveRight(mViewContainer, mSlidingWidth);
              break;
          // other cases
          }
      }
  
      // Animation Functions
  
      public void tableMoveLeft(final View container, final float newPos){
          ObjectAnimator moveLeft = ObjectAnimator.ofFloat(container, "translationX", 0, -newPos);
          moveLeft.setDuration(300);
          moveLeft.start();
      }
  
      public void tableMoveRight(final View container, final float newPos){
          ObjectAnimator moveRight = ObjectAnimator.ofFloat(container, "translationX", -newPos, 0);
          moveRight.setDuration(300);
          moveRight.start();
      }
  
      // other code
  
  }
  </code></pre>
  
  <p><strong>activity_main.xml</strong></p>
  
  <pre><code>&lt;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:background="@drawable/bg_menu"
      tools:context="${relativePackage}.${activityClass}" &gt;
  
      &lt;!-- other code --&gt;
  
      &lt;Button
          android:id="@+id/button_slider"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentRight="true"
          android:layout_alignParentTop="true"
          android:layout_marginRight="10dip"
          android:layout_marginTop="30dip"
          android:background="@drawable/move" /&gt;
  
      &lt;View
          android:id="@+id/transparent_container"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="#80800000"
          android:visibility="gone" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>slider_menu.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@drawable/image_info_bg_popup"
      android:orientation="vertical" &gt;
  
      &lt;!-- Other Code --&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>My Output on clicking the button</strong></p>
  
  <p><img src="https://i.stack.imgur.com/QBGtM.png" alt="Output"></p>
  
  <p>Using a <code>ScrollView</code> is not a solution because I dont want the user to freely scroll the view, and also there is a <code>ViewPager</code> in the main layout which will conflict with it. Please help. Thanks.</p>