I am trying to draw lines and rectangles and the line works perfectly, but when I try to draw the rectangles they doesn't show, so I commented the method and put the rectangles in the background of the layouts, but even they didn't show.
MainActivity.class
protected void onCreate (Bundle savedInstanceState {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
line = (LinearLayout)findViewById(R.id.line);
doLine DoLine = new doLine(line.getContext (),0.2,0.4,0.4);
line.addView(DoLine);
}
DoLine.class
public DoLine (Context context, double first, double second, double third){
super (context);
one = first;
two = second;
three = three;
}
#SuppressLink("DrawAllocation")
public void onDraw (Canvas canvas){
canvas.drawRGB (255,255,255);
Paint pincel1 = new Paint;
pincel1.setColor(getResources().getColor(R.color.yellow));
canvas.drawRect(0,10, getWidth(),40,pincel1);
pincel1.setColor(getResources().getColor(R.colot.green));
canvas.drawRect((float)(getWidth()*one),10, getWidth(),40,pincel1);
pincel1.setColor(getResources().getColor(R.color.blue));
canvas.drawRect((float)(getWidth()*one),10, (float)(getWidth()-(getWidth()*three)),40, pincel1);
activity_main.xml
<LinearLayout
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="#dcdcdc"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="#fdfdfd"
android:orientation="vertical"
android:padding="3dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:background="#90ffb200"
android:padding="5dp" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="5dp"
android:gravity="right"
android:text="#string/title"
android:textSize="17sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/line"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="5dp"
android:paddingRight="5dp" >
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="5dp">
<LineraLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal
<LinearLayout
android:id="#+id/rectyellow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/yellow
</LinearLayout>
<TextView
android:id="#+id/oneText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
<LinearLayout
android:id="#+id/rectblue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/blue"
</LinearLayout>
<TextView
android:id="#+id/twoText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
<LinearLayout
android:id="#+id/rectgreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/green"
</LinearLayout>
<TextView
android:id="#+id/threeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Three" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
I have been researching for many many days to find a solution and today i found it, I just needed to change the height of the layout to 40dp
android:layout_height="wrap_content"// change this to 40dp
mainActivity.xml
<LinearLayout
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="#dcdcdc"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="#fdfdfd"
android:orientation="vertical"
android:padding="3dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:background="#90ffb200"
android:padding="5dp" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="5dp"
android:gravity="right"
android:text="#string/title"
android:textSize="17sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/line"
android:layout_width="match_parent"
android:layout_height="wrap_content"// change this to 40dp
android:orientation="vertical"
android:paddingLeft="5dp"
android:paddingRight="5dp" >
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="5dp">
<LineraLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal
<LinearLayout
android:id="#+id/rectyellow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/yellow
</LinearLayout>
<TextView
android:id="#+id/oneText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
<LinearLayout
android:id="#+id/rectblue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/blue"
</LinearLayout>
<TextView
android:id="#+id/twoText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
<LinearLayout
android:id="#+id/rectgreen"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:background="#drawable/green"
</LinearLayout>
<TextView
android:id="#+id/threeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Three" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
https://www.dropbox.com/s/8dvmgv1k37tnm9f/Sin%20t%C3%ADtulo.png
it's right:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout line = (LinearLayout)findViewById(R.id.line);
DoLine doLine = new DoLine(line.getContext (),0.2,0.4,0.4);
line.addView(doLine);
}
public class DoLine extends View {
double one;
double two;
double three;
public DoLine(Context context, double first, double second, double third) {
super(context);
one = first;
two = second;
three = third;
}
#SuppressLint("DrawAllocation")
public void onDraw(Canvas canvas) {
canvas.drawRGB(255, 255, 255);
Paint pincel1 = new Paint();
pincel1.setColor(Color.YELLOW);
canvas.drawRect(0, 10, getWidth(), 40, pincel1);
pincel1.setColor(Color.GREEN);
canvas.drawRect((float) (getWidth() * one), 10, getWidth(), 40, pincel1);
pincel1.setColor(Color.BLUE);
canvas.drawRect((float) (getWidth() * one), 10, (float) (getWidth() - (getWidth() * three)), 40, pincel1);
}
}
}
Related
I created a new custom view that looks like this
public class SearchCategoryPanel extends RelativeLayout {
private boolean hasRetrieved = false;
private GridLayout categoryContainer;
private TextView scpLoadingText;
public static final int HEIGHT = 360;
private ArrayList<OnCategoryItemClickListener> onCategoryItemClickListeners = new ArrayList<OnCategoryItemClickListener>();
public SearchCategoryPanel(Context context) {
super(context);
init();
}
public SearchCategoryPanel(Context context, AttributeSet attrs) {
super(context, attrs);
Log.i(SearchCategoryPanel.class.getSimpleName(), this.getTop() + "");
init();
}
public SearchCategoryPanel(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public void init() {
inflate(getContext(), R.layout.search_category_panel, this);
this.scpLoadingText = (TextView) findViewById(R.id.sCategoryPanelLoadingText);
this.categoryContainer = (GridLayout) findViewById(R.id.sCategoryContainer);
this.setVisibility(View.GONE);
}
public void show() {
this.setVisibility(View.VISIBLE);
}
public void hide() {
this.setVisibility(View.GONE);
}
public void setProcessing(boolean on) {
if(!on) {
this.scpLoadingText.setVisibility(View.GONE);
} else {
this.scpLoadingText.setVisibility(View.VISIBLE);
}
}
public void addCategoryItemUsingVo(CategoryVo categoryVo) {
CategoryItem item = new CategoryItem(getContext());
item.setCategoryVo(categoryVo);
item.setOnItemClickListener(new CategoryItem.OnClickListener() {
#Override
public void onClick(CategoryVo categoryVo) {
triggerOnCategoryItemClickListener(categoryVo);
}
});
this.categoryContainer.addView(item);
}
public void removeAllItems() {
this.categoryContainer.removeAllViews();
}
public boolean hasRetrieved() {
return hasRetrieved;
}
public interface OnCategoryItemClickListener {
public void onClick(CategoryVo categoryVo);
}
public void setOnCategoryItemClickListener(OnCategoryItemClickListener listener) {
this.onCategoryItemClickListeners.add(listener);
}
private void triggerOnCategoryItemClickListener(CategoryVo vo) {
for(OnCategoryItemClickListener listener : onCategoryItemClickListeners ) {
listener.onClick(vo);
}
}
}
Then, I try to call the getHitRect
Rect rectF = new Rect();
searchCategoryPanel.getHitRect(rectF);
Log.i(ARModeActivity.class.getSimpleName(), "Rect: " + rectF.toString());
The log returns strange value: Rect: Rect(0, 0 - 1920, 1164). this means the relative layout covers the whole screen which is not correct.
The SearchCategoryPanel xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#7F000000"
android:layout_alignParentBottom="true"
android:maxHeight="360dp"
android:layout_height="160dp">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Search Category"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="24dp"/>
<TextView
android:id="#+id/sCategoryPanelLoadingText"
android:layout_width="wrap_content"
android:textSize="24sp"
android:textColor="#android:color/white"
android:layout_height="match_parent"
android:text="Loading.."/>
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<GridLayout
android:id="#+id/sCategoryContainer"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content">
</GridLayout>
</HorizontalScrollView>
</LinearLayout>
</RelativeLayout>
The relative layout only has 360dp in height, andfull width (look at the xml). but it returns the wrong value. I have read about onMeasure and onSizeChanged, but nothing helped
Here How I call the search_category_panel layout:
<?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:orientation="vertical"
android:layout_height="match_parent"
android:id="#+id/rootArMode"
tools:context="com.imav.ARModeActivity">
<RelativeLayout
android:id="#+id/rlInfoARMode"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:background="#7F000000"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:orientation="vertical"
android:layout_centerHorizontal="true"
android:gravity="center"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#FFF"
android:textSize="24sp"
android:text="Interaction Guide"/>
<LinearLayout
android:gravity="left"
android:layout_width="match_parent"
android:layout_marginBottom="4sp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textColor="#FFF"
android:textSize="18sp"
android:textStyle="bold"
android:text="Select: "/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textColor="#FFF"
android:textSize="16sp"
android:text="Tap on object with 1 finger "/>
</LinearLayout>
<LinearLayout
android:gravity="left"
android:layout_width="match_parent"
android:layout_marginBottom="4sp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textColor="#FFF"
android:textSize="18sp"
android:textStyle="bold"
android:text="Move: "/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textColor="#FFF"
android:textSize="16sp"
android:text="Touch and Drag Object with 1 finger "/>
</LinearLayout>
<LinearLayout
android:gravity="left"
android:layout_marginBottom="4sp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textColor="#FFF"
android:textSize="18sp"
android:textStyle="bold"
android:text="Rotate: "/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textColor="#FFF"
android:textSize="16sp"
android:text="Touch and drag object with 2 fingers "/>
</LinearLayout>
<LinearLayout
android:gravity="left"
android:layout_width="match_parent"
android:layout_marginBottom="4sp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textColor="#FFF"
android:textSize="18sp"
android:textStyle="bold"
android:text="Scale: "/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textColor="#FFF"
android:textSize="16sp"
android:text="Touch and pinch object with 2 fingers "/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<Button
android:id="#+id/btnCloseArMode"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="15dp"
android:background="#drawable/ic_clear_white_24dp" />
<RelativeLayout
android:id="#+id/rlOpenActionBar"
android:layout_width="55dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true">
<Button
android:id="#+id/btnOpenActionBar"
android:background="#drawable/ic_keyboard_backspace_white_24dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="55dp"
android:id="#+id/rlActionBar"
android:layout_height="match_parent"
android:visibility="gone"
android:background="#7F000000"
android:layout_alignParentRight="true">
<Button
android:id="#+id/btnInfoArMode"
android:layout_width="wrap_content"
android:background="#drawable/ic_error_white_24dp"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<Button
android:id="#+id/btnAddObjArMode"
android:layout_marginBottom="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_add_white_24dp"
android:layout_below="#+id/btnSaveSceneArMode" />
<Button
android:id="#+id/btnSaveSceneArMode"
android:layout_marginBottom="8dp"
android:layout_width="wrap_content"
android:background="#drawable/ic_add_a_photo_white_24dp"
android:layout_height="wrap_content" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:id="#+id/pbSaveSceneArMode"/>
<Button
android:id="#+id/btnShareARMode"
android:layout_width="wrap_content"
android:background="#drawable/ic_share_white_24dp"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<Button
android:id="#+id/btnTrashArMode"
android:layout_width="wrap_content"
android:background="#drawable/ic_delete_white_24dp"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
<com.imav.view.SearchCataloguePanel
android:id="#+id/searchCataloguePanelArMode"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</com.imav.view.SearchCataloguePanel>
<com.imav.view.SearchCategoryPanel
android:id="#+id/searchCategoryPanelArMode"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</com.imav.view.SearchCategoryPanel>
</RelativeLayout>
My first approach would be not to override the onMeasure() in your custom view SearchCategoryPanel. Because you are forcing a different dimension than the ones provided by the xml.
I have a custom PrintDocumentAdapter and draw pages on my own, so I should draw xml layout on the page canvas:
private void drawPage(PdfDocument.Page page, List<Object> objects,
int pageNumber) {
Canvas canvas = page.getCanvas();
...
}
there is an TableLayout in my xml. I want table width to fill the entire page but it exceed the page if the width bigger than page width or is smaller than the page if its width is smaller than the page width. I used both wrap_content and match_parent but none of them worked. I even tried fix width and height.
private void drawPage(PdfDocument.Page page, List<Payment> payments,
int pageNumber) {
Canvas canvas = page.getCanvas();
PdfDocument.PageInfo pageInfo = page.getInfo();
canvas.save();
canvas.translate(leftMargin , topMargin);
FrameLayout frameLayout = new FrameLayout(context);
frameLayout.setLayoutParams(new ViewGroup.LayoutParams(200, 200));
LayoutInflater li = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = li.inflate(R.layout.payments_table_layout, null);
v.setLayoutParams(new
FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
TableLayout tableLayout = (TableLayout) v.findViewById(R.id.payments_table_layout);
for(int i= 0 ; i< objects.size(); ++i){
//... some code
}
frameLayout.addView(v);
frameLayout.measure(200 , 200);
frameLayout.layout(100, 100, 100, 100);
frameLayout.draw(canvas);
canvas.restore();
}
R.layout.payments_table_layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="50dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="some text"
style="#style/CustomFont.Wave"/>
</FrameLayout>
<TableLayout
android:id="#+id/payments_table_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:stretchColumns="*"
android:layout_weight="1">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#ccc">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="some text"
android:layout_gravity="center"
android:background="#drawable/table_border"
android:padding="4dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="some text"
android:layout_gravity="center"
android:background="#drawable/table_border"
android:padding="4dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="some text"
android:layout_gravity="center"
android:background="#drawable/table_border"
android:padding="4dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="some text"
android:layout_gravity="center"
android:background="#drawable/table_border"
android:padding="4dp"/>
</TableRow>
</TableLayout>
</LinearLayout>
Now the Result:
I shouldn't stretch all columns of TableLayout so I changed this attribute to :
android:stretchColumns="1,3,7"
android:shrinkColumns="5"
and set the layout width to width of the page like this ( we should care the dimension unit): in my customPrintDocumentAdapter
#Override
public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras) {
myPdfDocument = new PrintedPdfDocument(context, newAttributes);
pageHeight =
newAttributes.getMediaSize().getHeightMils()/1000 * 72;
pageWidth =
newAttributes.getMediaSize().getWidthMils()/1000 * 72;
...
}
and my new drawPage method:
private void drawPage(PdfDocument.Page page, List<Payment> payments,
int pageNumber) {
...
frameLayout.setLayoutParams(new ViewGroup.LayoutParams(pageWidth, pageHeight));
...
}
please try below xml , in which I used weightsum and layout weight in TableRow and its child textviews
android:weightSum="4"
android:layout_width="0dp"
android:layout_weight="1"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="50dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="some text"
/>
</FrameLayout>
<TableLayout
android:id="#+id/payments_table_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:stretchColumns="*"
android:layout_weight="1">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="4"
android:layout_gravity="center_horizontal"
android:background="#ccc">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="some text"
android:layout_gravity="center"
android:background="#color/colorAccent"
android:padding="4dp"
/>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="some text"
android:layout_gravity="center"
android:background="#color/colorAccent"
android:padding="4dp"/>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="some text"
android:layout_gravity="center"
android:background="#color/colorAccent"
android:padding="4dp"/>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="some text"
android:layout_gravity="center"
android:background="#color/colorAccent"
android:padding="4dp"/>
</TableRow>
</TableLayout>
</LinearLayout>
I'm drawing lines in relative Layout.To do this, I add line views add to relative layout. But when I add drawed lines to relative layouts the Relative Layout's height changes. Why ? Thanks in advance for your help ! :)
layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="com.mobisoft.kelimebul.Local.Oyun"
android:backgroundTint="#ffffcd8d"
android:backgroundTintMode="multiply"
android:background="#ffff9f63"
android:padding="7dp"
android:id="#+id/s"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/relative"
android:touchscreenBlocksFocus="true"
android:nestedScrollingEnabled="true"
android:layout_weight="1">
<GridView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/gameBoard"
android:listSelector="#00000000"
android:background="#color/tahta_rengi"
android:scrollbars="none"
android:fastScrollAlwaysVisible="false"
android:fastScrollEnabled="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:drawSelectorOnTop="true" />
</RelativeLayout>
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/horizontalScrollView"
android:background="#color/tahta_rengi"
android:layout_weight="1">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/scrolinear">
</LinearLayout>
</HorizontalScrollView>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/backgroundColor"
android:backgroundTint="#color/backgroundColorTint"
android:visibility="visible"
android:layout_weight="1">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/timeIcon"
android:src="#drawable/clock"
android:scaleType="fitCenter"
android:layout_gravity="center_horizontal"
android:layout_marginRight="4dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/time"
android:gravity="center_vertical|center|right|center_horizontal"
android:textSize="#dimen/score_textsize"
android:layout_gravity="right"
android:textAlignment="center"
android:layout_alignParentRight="true" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/RemainingWordN"
android:id="#+id/textView5"
android:textSize="#dimen/score_textsize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/remainingNumber"
android:textSize="#dimen/score_textsize" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
Activity.java // Some part code of this activity
DrawView drawView;
drawView = new DrawView(getApplicationContext(), locs, view.getWidth(), colors.get(lineColor));
RelativeLayoutOfLines.addView(drawView); // Add view to relativeLayouts
DrawView.java
public class DrawView extends View {
Paint paint = new Paint();
float locs[];
int strokeWidth;
int color;
public DrawView(Context context, float locs[], int strokeWidth, int color) {
super(context);
this.locs = locs;
this.strokeWidth = strokeWidth;
this.color = color;
}
#Override
public void onDraw(Canvas canvas) {
paint.setColor(getContext().getResources().getColor(color));
paint.setAlpha(100);
paint.setStrokeWidth(strokeWidth);
canvas.drawLine(locs[0], locs[1], locs[2], locs[3], paint); // left, top, right, bottom
canvas.save();
canvas.restore();
}
}
Before Drawing:
https://www.dropbox.com/s/oo79d8rvp4sa2nj/s.PNG?dl=0
After Drawing :
https://www.dropbox.com/s/vawjsxcbi6gd2go/s2.PNG?dl=0
A quick note about my application. This is an app that uses an API to get server requests about specific players for a game called League of Legends (LoL)
I recently changed my code from a static layout of 10 pre-set most recent matches to a ListView in order to avoid cludder as well in case a player did not have 10 recent matches.
The issue I am having with this ListView, is that when it is created, you can not scroll up and down through it. That is to say that it is created in a very small height, and when you scroll in it, the page doesn't scroll, the ListView itself scrolls. This is not desirable. I would rather have the user scroll the whole screen than just the small portion of the ListView.
I constructed my xml file like so:
<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal"
android:paddingLeft="#dimen/activity_horizontal_margin">
<EditText
android:id="#+id/summoner_name"
android:layout_width="210dp"
android:layout_height="wrap_content"
android:hint="Summoner Name"
android:imeOptions="actionSend"
android:lines="1" />
<Spinner
android:id="#+id/regions"
android:layout_width="60dp"
android:layout_height="wrap_content" />
<Button
android:id="#+id/search_button"
android:layout_width="45dp"
android:layout_height="45dp"
android:background="#drawable/searchbuttononclick" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="9dp"
android:orientation="horizontal"
android:paddingLeft="#dimen/activity_horizontal_margin">
<ImageView
android:id="#+id/leagueicon"
android:layout_width="160dp"
android:layout_height="150dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="20dp" />
<TextView
android:id="#+id/summoner_name_after_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textSize="22dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="#+id/league_tier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ff0060a8"
android:textSize="18dp" />
<TextView
android:id="#+id/league_points"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:textSize="18dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="#+id/ranked_wins"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ff00b515"
android:textSize="18dp" />
<TextView
android:id="#+id/slash_between_wins_and_losses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:textColor="#ff817a81"
android:textSize="18dp" />
<TextView
android:id="#+id/ranked_losses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:textColor="#ffb5000f"
android:textSize="18dp" />
</LinearLayout>
<TextView
android:id="#+id/what_were_you_last_season"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textColor="#ff817a81"
android:textSize="18dp" />
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:textSize="16dp"
android:id="#+id/normal_title"
android:textStyle="bold"
android:textColor="#ff000000" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="120dp"
android:orientation="horizontal"
android:baselineAligned="false">
<LinearLayout
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="120dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="38dp"
android:paddingLeft="5dp"
android:id="#+id/normal_wins"
android:gravity="center_vertical"
android:textSize="16dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="2dp"
android:id="#+id/normal_space_one"/>
<TextView
android:layout_width="match_parent"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:textSize="16dp"
android:id="#+id/normal_kills"
android:layout_height="38dp"
/>
<TextView
android:layout_width="match_parent"
android:id="#+id/normal_space_two"
android:layout_height="2dp"/>
<TextView
android:layout_width="match_parent"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:id="#+id/normal_assists"
android:textSize="16dp"
android:layout_height="38dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="120dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="38dp"
android:gravity="center_vertical"
android:id="#+id/normal_wins_value"
android:paddingLeft="5dp"
android:textSize="16dp"
/>
<TextView
android:layout_width="match_parent"
android:id="#+id/normal_space_three"
android:layout_height="2dp"/>
<TextView
android:layout_width="match_parent"
android:gravity="center_vertical"
android:id="#+id/normal_kills_value"
android:textSize="16dp"
android:paddingLeft="5dp"
android:layout_height="38dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="2dp"
android:id="#+id/normal_space_four"/>
<TextView
android:layout_width="match_parent"
android:id="#+id/normal_assists_value"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:textSize="16dp"
android:layout_height="38dp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="120dp"
android:orientation="vertical"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="horizontal"
android:baselineAligned="false">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="120dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="38dp"
android:paddingLeft="5dp"
android:id="#+id/normal_minion_kills"
android:gravity="center_vertical"
android:textSize="16dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="2dp"
android:id="#+id/normal_space_five"/>
<TextView
android:layout_width="match_parent"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:textSize="14dp"
android:id="#+id/normal_neutral_minion_kills"
android:layout_height="38dp"
android:layout_gravity="center_horizontal"/>
<TextView
android:layout_width="match_parent"
android:id="#+id/normal_space_six"
android:layout_height="2dp"/>
<TextView
android:layout_width="match_parent"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:id="#+id/normal_turrets_destroyed"
android:textSize="12dp"
android:layout_height="38dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="120dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="38dp"
android:paddingLeft="5dp"
android:gravity="center_vertical"
android:id="#+id/normal_minion_kills_value"
android:textSize="16dp"
/>
<TextView
android:layout_width="match_parent"
android:id="#+id/normal_space_seven"
android:layout_height="2dp"/>
<TextView
android:layout_width="match_parent"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:id="#+id/neutral_minion_kills_value"
android:textSize="16dp"
android:layout_height="38dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="2dp"
android:id="#+id/normal_space_eight"/>
<TextView
android:layout_width="match_parent"
android:id="#+id/normal_turrets_destroyed_value"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:textSize="16dp"
android:layout_height="38dp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<com.ryanfolz.riotgamesapi.SwagObListView
android:id="#+id/list"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="20dp"></LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
As you see, I created a custom ListView called "SwagObListView"
Here is the code for that:
public class SwagObListView extends ListView implements AdapterView.OnItemClickListener {
private List<SwagOb> swagList;
private SwagObClickListener swagClicked;
public SwagObListView(Context context) {
super(context);
}
public SwagObListView(Context context, AttributeSet attrs) {
super(context, attrs);
this.swagList = swagList;
this.swagClicked = swagClicked;
}
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if (swagClicked != null) {
swagClicked.onConnectionClicked(swagList.get(i));
}
}
public void setOnSwagObClickListener(SwagObClickListener c){
this.swagClicked = c;
}
public void setSwag(List<SwagOb> swagList) {
this.swagList = swagList;
SwagObAdapter swagDapter = new SwagObAdapter(getContext(), swagList);
setAdapter(swagDapter);
setOnItemClickListener(this);
}
}
As for the SwagOb class, here is the code for that:
public class SwagOb {
private String gameType;
private Drawable championPicturePlayed;
private String kills;
private String deaths;
private Drawable[] summonerSpells;
private String assists;
private String cs;
private String gold;
private boolean won;
private Drawable itemOne, itemTwo, itemThree, itemFour, itemFive, itemSix;
private Drawable[] tempDrawable;
private Drawable[] tempDrawable2;
private String[] tempString;
private SearchPlayerFragment activty;
private CollectUserData data;
public SwagOb(String gameType, Drawable championPicturePlayed, String kills, String deaths, Drawable[] summonerSpells,
String assists, String cs, String gold, boolean won, Drawable itemOne, Drawable itemTwo, Drawable itemThree, Drawable itemFour,
Drawable itemFive, Drawable itemSix, Drawable[] tempDrawable, Drawable[] tempDrawable2, String[] tempString, SearchPlayerFragment activity, CollectUserData data){
this.gameType = gameType;
this.championPicturePlayed = championPicturePlayed;
this.kills = kills;
this.deaths = deaths;
this.summonerSpells = summonerSpells;
this.itemFive = itemFive;
this.itemTwo = itemTwo;
this.itemOne = itemOne;
this.itemThree = itemThree;
this.itemFour = itemFour;
this.itemSix = itemSix;
this.assists = assists;
this.cs = cs;
this.gold = gold;
this.won = won;
this.tempDrawable = tempDrawable;
this.tempDrawable2 = tempDrawable2;
this.tempString = tempString;
this.activty = activity;
this.data = data;
}
(This also has getters and setters but that isn't important.)
Anyone know any ideas as to why this is acting this way?
Android does not allow to add ListView inside ScrollView. Possible workaround for this will be remove scrollview and adding top content to listivew header and bottom content into listview footer.
In your scroll view add this property That will do the trick
android:fillViewport="true"
i have a gridview to show images with button, but i have a problem, it only shows the first row, and i send it data for 3 rows..
This is my layout code:
<?xml version="1.0" encoding="utf-8"?><!-- To make screen scroll in vertical direction -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bootstrapthumbnail="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:background="#drawable/fondodroid2"
android:orientation="vertical">
<!-- Main layout -->
<ScrollView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fefdff"
android:layout_marginLeft="#dimen/login_activity_horizontal_margin"
android:layout_marginRight="#dimen/login_activity_horizontal_margin"
android:layout_marginTop="#dimen/login_activity_vertical_margin"
android:padding="#dimen/login_activity_horizontal_margin"
android:id="#+id/linearLayout">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="true"
android:paddingTop="0dp"
android:paddingBottom="0dp"
android:layout_marginBottom="#dimen/login_activity_vertical_margin"
android:weightSum="1">
<ImageView
android:layout_width="#dimen/login_activity_logo"
android:layout_height="#dimen/login_activity_logo"
android:id="#+id/imageView"
android:src="#drawable/logo"
android:contentDescription="Icon GG"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/files"
android:id="#+id/textView"
android:textSize="#dimen/login_activity_text"
android:textColor="#android:color/black"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/imageView"
android:layout_marginLeft="10dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:id="#+id/relativeLayout">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:background="#686868"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:text="#string/sign_string"
android:textSize="#dimen/login_activity_vertical_margin"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/linearSign"
android:layout_centerInParent="true"
android:background="#cccccc"
android:visibility="gone">
<ImageView
android:id="#+id/sign_thumb"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_margin="3dp"></ImageView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_below="#+id/sign_thumb"
android:layout_alignEnd="#+id/sign_thumb">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Eliminar"
android:id="#+id/deleteButton"
android:background="#cc6b67"
android:textStyle="bold"
android:layout_marginBottom="8dp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:id="#+id/relativeLayout2"
android:layout_marginTop="16dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:background="#686868"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:text="#string/images"
android:textSize="#dimen/login_activity_vertical_margin"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/linearLayout2">
<GridView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/gridImages"
android:numColumns="2"
android:layerType="hardware"
android:verticalSpacing="1dp"
android:horizontalSpacing="1dp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="#dimen/login_activity_logo_h"
android:layout_height="#dimen/login_activity_logo_v"
android:id="#+id/imageView2"
android:src="#drawable/logo"
android:layout_below="#+id/linearLayout"
android:layout_alignRight="#+id/linearLayout"
android:layout_marginTop="#dimen/login_activity_vertical_margin"
android:layout_marginBottom="#dimen/login_activity_vertical_margin"
android:contentDescription="#string/logo" />
</RelativeLayout>
</ScrollView>
</LinearLayout>
In the adapter i dont have any strangle, but if you need i copy it here..I try with fill_parent wrap_content etc but nothing works..
Edit: the adapter code:
public class GridAdapter extends BaseAdapter {
private LayoutInflater inflater;
private Activity activity;
private List<String> images = new ArrayList<String>();
private OnDeleteItem mListener;
public interface OnDeleteItem {
public void onDeleteItemClick(String path);
}
public GridAdapter(Activity inyectActivity, List<String> listImages) {
activity = inyectActivity;
images = listImages;
inflater = LayoutInflater.from(activity);
mListener = (ReviewFilesActivity) activity;
}
public void notifyDataSetChanged(List<String> dataImages) {
images = dataImages;
super.notifyDataSetChanged();
}
public View getView(final int position, View convertView, ViewGroup parent) {
GridViewHolder vHolder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.grid_view, null);
vHolder = new GridViewHolder(convertView, mListener);
vHolder.image.setImageBitmap(ImagesUtilities.decodeSampledBitmapFromResource(images.get(position), 400, 400));
vHolder.path = images.get(position);
vHolder.delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mListener.onDeleteItemClick(images.get(position));
}
});
} else {
vHolder = (GridViewHolder) convertView.getTag();
}
return convertView;
}
#Override
public int getCount() {
return images.size();
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
static class GridViewHolder {
public GridViewHolder(View view, OnDeleteItem listener) {
ButterKnife.inject(this, view);
}
#InjectView(R.id.grid_item_image)
ImageView image;
#InjectView(R.id.deleteButton)
Button delete;
String path;
public String getPath() {
return path;
}
}
}
Edit2:
I did more simply the XML, but the rows dont show.
<?xml version="1.0" encoding="utf-8"?><!-- To make screen scroll in vertical direction -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:background="#drawable/fondodroid2"
android:orientation="vertical">
<!-- Main layout -->
<ScrollView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fefdff"
android:layout_marginLeft="#dimen/login_activity_horizontal_margin"
android:layout_marginRight="#dimen/login_activity_horizontal_margin"
android:layout_marginTop="#dimen/login_activity_vertical_margin"
android:padding="#dimen/login_activity_horizontal_margin"
android:id="#+id/linearLayout">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="true"
android:paddingTop="0dp"
android:paddingBottom="0dp"
android:layout_marginBottom="#dimen/login_activity_vertical_margin"
android:weightSum="1">
<ImageView
android:layout_width="#dimen/login_activity_logo"
android:layout_height="#dimen/login_activity_logo"
android:id="#+id/imageView"
android:src="#drawable/logo"
android:contentDescription="Icon GG"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/files"
android:id="#+id/textView"
android:textSize="#dimen/login_activity_text"
android:textColor="#android:color/black"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/imageView"
android:layout_marginLeft="10dp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/relativeLayout"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:text="#string/sign_string"
android:textSize="#dimen/login_activity_vertical_margin"
android:textStyle="bold"
android:background="#686868"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:gravity="center"
android:id="#+id/textView3" />
<ImageView
android:id="#+id/sign_thumb"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:layout_alignParentEnd="false"
android:visibility="gone" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Eliminar"
android:id="#+id/deleteButton"
android:background="#cc6b67"
android:textStyle="bold"
android:layout_alignBottom="#+id/textView3"
android:layout_alignParentStart="true"
android:visibility="gone" />
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:id="#+id/relativeLayout2"
android:layout_marginTop="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textColor="#android:color/white"
android:text="#string/images"
android:textSize="#dimen/login_activity_vertical_margin"
android:textStyle="bold"
android:background="#686868"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:gravity="center"
android:id="#+id/textView2" />
<GridView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="#+id/gridImages"
android:numColumns="2"
android:verticalSpacing="1dp"
android:horizontalSpacing="1dp"
android:layout_alignParentLeft="false"
android:layout_marginLeft="0dp"
android:layout_below="#+id/textView2" />
</RelativeLayout>
</LinearLayout>
<ImageView
android:layout_width="#dimen/login_activity_logo_h"
android:layout_height="#dimen/login_activity_logo_v"
android:id="#+id/imageView2"
android:src="#drawable/logo"
android:layout_below="#+id/linearLayout"
android:layout_alignRight="#+id/linearLayout"
android:layout_marginTop="#dimen/login_activity_vertical_margin"
android:layout_marginBottom="#dimen/login_activity_vertical_margin"
android:contentDescription="#string/logo" />
</RelativeLayout>
</ScrollView>
</LinearLayout>
Here is some simplified example to achieve needed layout
<?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:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_icon" />
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/sign_thumb"
android:layout_width="match_parent"
android:layout_height="100dp"
android:src="#drawable/ic_icon" />
<Button
android:id="#+id/deleteButton"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<GridView
android:id="#+id/gridImages"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="2" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_icon" />
</LinearLayout>