How to make the left and right padding of the android-seekbar disappear - android-seekbar

I have the following xml:
<SeekBar android:id="#+id/sk"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="120"
android:background="#44ff0000"
android:paddingLeft="0dp"
android:paddingRight="0dp"
/>
Why the seekbar still has spaces as the picture shows, how can I make them disappear?
the picture

Use following lines in java.
SeekBar sk = (SeekBar)findViewByID(R.id.sk);
sk.setPadding(0,0,0,0);

Just use these 2 lines in your Seekbar xml
android:paddingStart="0dp"
android:paddingEnd="0dp"
Answere in: https://stackoverflow.com/a/42509109/5819451

Related

How to display bars from left to right with a fixed bar gap?

I want to display bars from left to right with a fixed bar gap, rather than display them evenly.
I have tried to add barCategoryGap or barGap prop with fixed number, but no influence for the chart like this:
And my code is:
<BarChart data={data} barSize={10} barCategoryGap={1}>
<YAxis
...some props
/>
<Tooltip />
<Bar dataKey="responseTime">
{data.map((item, index) => (
<Cell fill={item.isPass ? '#3c763d' : '#a94442'} key={index} />
))}
</Bar>
</BarChart>
In your graph, you don't have any XAxis specified to group your bars into categories. Because of this, the props barGap and barCategoryGap won't work, since there is no category to make changes on.
To solve your problem, you should add the missing XAxis which datakey would be a prop in your data object array, that shares the same object where your Bars values come from so that they can be regrouped. Afterwards you can "play" around with the gap between the different bars, just like a demo found on Recharts for Bars.

Why do AbsoluteLayout.LayoutBounds work incorrect in Xamarin?

I don't understand why is there so much space before the end of the screen(photo attached, platform - Android).
It looks like AbsoluteLayout fills not all the space of the screen, but it's not true.Where are also spaces between 'White' buttons(one button should take 20% of the screen; first starts after 4% from the left edge of the screen, second - after 28%: 28% - 4% -20% = 4% free space between buttons)????
Here is xaml code:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="PokerCalculator.OutsCalculator"
BackgroundColor="#131313">
<AbsoluteLayout BackgroundColor="HotPink">
<Label Text="Number of outs:"
FontSize="Medium"
AbsoluteLayout.LayoutBounds="0.04,0,0.3,0.18"
AbsoluteLayout.LayoutFlags="SizeProportional, PositionProportional"
BackgroundColor="Aqua"/>
<Label x:Name="lblOutNumber"
Text="15"
AbsoluteLayout.LayoutBounds="0.35,0,0.18,0.18"
AbsoluteLayout.LayoutFlags="SizeProportional, PositionProportional"
BackgroundColor="Azure"/>
<Button x:Name="btnBack"
Text="BACK"
Clicked="btnBack_Clicked"
AbsoluteLayout.LayoutBounds="0.7,0,0.28,0.18"
AbsoluteLayout.LayoutFlags="SizeProportional, PositionProportional"
BackgroundColor="Fuchsia"/>
<Button BackgroundColor="White"
AbsoluteLayout.LayoutBounds="0.04,0.2,0.20,0.28"
AbsoluteLayout.LayoutFlags="All"/>
<Button BackgroundColor="White"
AbsoluteLayout.LayoutBounds="0.28,0.2,0.20,0.28"
AbsoluteLayout.LayoutFlags="All"/>
<Button BackgroundColor="White"
AbsoluteLayout.LayoutBounds="0.52,0.2,0.20,0.28"
AbsoluteLayout.LayoutFlags="All"/>
<Button BackgroundColor="White"
AbsoluteLayout.LayoutBounds="0.76,0.2,0.20,0.28"
AbsoluteLayout.LayoutFlags="All"/>
</AbsoluteLayout>
</ContentPage>
photo
Photo(mockup)
As discussed on here forum
Absolute layout proportional does not work/calculated as what you expect. Your intention can be achieved using the relativelayout instead.
Lets say that you set X = 0.5 and Width = 0.5.
With your intention you might be expecting the element's X to start from the center and filling the second right half of the absolutelayout bound? No.
The answer is that the element will be 50% width of the layout bound and be right in the center. Making the X position such as (0.5 * absolutelayoutWidth) - (0.5 * elementWidth) (formula is something like this i guess?)
I suggest using relativelayout
As a late answer, I've put a nuget package with a fork of AbsoluteLayout but working in a more predictable way.
Install nuget package SmartMachines.AbsoluteLayout, add namespace xmlns:sm="clr-namespace:SmartMachines;assembly=AbsoluteLayout" and you will have exactly same AbsoluteLayout as native Xamarin, but with expected Proportional alignment behavior.
Hope that will save other people several hours on googling and debugging.

What properties it is necessary to set view1, so that it fills the rest of the window?

What properties it is necessary to set view1, so that it fills the rest of the window?
<Alloy>
<Window>
<View id="view1">
</View>
<View id="view2" height="50">
</View>
</Window>
</Alloy>
<Alloy>
<Window>
<View id="view1" top="0" bottom="50" width="100%">
</View>
<View id="view2" height="50" bottom="0" width="100%">
</View>
</Window>
</Alloy>
Also it is good to put the dimensions in the style (TSS) file instead of putting them in the view XML file. If this resolves your query then mark it as an answer for the reference for the rest of the community.
There are multiple ways to fill dimensions. It depends on what kind of layout type you have used like - vertical, horizontal or composite (default).
Vertical
Aligns children below each other.
You can control width, left, right, top & bottom properties. (bottom property doesn't work for last child)
Last child can occupy rest of the vertical height of parent.
Horizontal:
Aligns children from left-to-right in horizontal plane.
Can control left, right, top & bottom properties (right property doesn't work for last child).
Last child can occupy remaining width of view
Composite or default
Most flexible if you have not oriented UI.
Can keep views anywhere using top,left,right,bottom.
Assigning left & right only will define the width. Adding width with left & right will obey width keeping left & right restrictions.
-- e.g. if left & right = 20 & width=Ti.UI.SIZE, then view will start from left & will have width as Ti.UI.SIZE & will not go beyond right=20
Same rule as above applies for height as well.

Wrapping text around an image with React-Native

I try to create a View with an Image and a Text component that wraps around the Image component.
My styling:
textContainer: {
flexDirection: 'row',
},
text: {
flex: 10,
},
image: {
flex:1,
height: 180,
width: 150,
margin: 10,
borderColor: '#ccc',
borderWidth: 1,
}
My component:
<ScrollView style={styles.contentContainer} >
{this.props.content.title_1 ? <Text style={styles.title}>{this.props.content.title_1}</Text> : null}
<View style={styles.textContainer}>
{this.props.content.text_1 ? <Text style={styles.text}>{this.props.content.text_1}</Text> : null}
{this.props.content.image_1 ? <Image width={null} height={null} style={styles.image} source={this.props.content.image_1} /> : null}
</View>
</ScrollView>
This is what the result: (not wrapping at all haha)
In the image beneath here, I quickly hacked the little image into the text. But I can't get the text to be wrapped around..
I hope anyone can help me in the right direction!
This is really hard but there is one weird way to do this.. Try the following. It worked for me but place I am doing this is too deep in the other views.:
<Text>
<View style={{width:400, height:100, flex:1, flexDirection:'row'}}>
<Image source={require('')}/>
<Text>Your Content Here</Text>
</View>
</Text>
Good luck. Please put a comment letting us know if it worked.
On android you cannot place a View inside Text, but you can place an Image, here is an example:
<Text>
<Image source="" />
<Text> Insert your text here </Text>
</Text>
Although this is an old post, I'll add this because I have recently had this problem and found a totally different approach that works for me. I don't have the code to hand (I can get it if anyone wants it), but the principle was this:
Requirement: to have a picture in the top left corner of the screen that takes up about half the screen width, with text starting to the right of it and then continuing beneath it for the whole width of the screen.
In XML, create a RelativeLayout containing an ImageView (IV) on the left and a TextView (TVA), set to wrap content, on the right. Then create another TextView (TVB) to sit below the Relative Layout. TVA is for the text beside the image and TVB for the text beneath it.
Put your image in IV. Then measure the height of IV in pixels (dpi). Call this height IVh
Put some of your text in TVA. As long as there is enough text to wrap over several lines, it doesn't really matter how much. Then measure the height of TVA in pixels. Call this height TVh
Compare IVh with TVh. If IVh=TVh then you have just the right amount of text to sit alongside your image. If TVh = IVh x 2 then you have twice as much text as you should have. And so on.
Adjust the number of words accordingly and put the right number into TVA, replacing what was there, then put the rest of the text in TVB.
You will need to play with margins and padding to allow an adequate margin around the image. Also, in steps 3 and 4 after you have put your image into ImageView or your text into TextView, you will need a delay before measuring the heights, to allow the display to be created - otherwise the measurement will be done too soon, before there is anything on the screen, and will return a height of zero. I found 200 milliseconds quite adequate and it's too fast for the user to notice a delay.

QLabel showing an image inside a QScrollArea

I've successfully implemented a Image Viewer (for DICOM) in Qt.
I can see the image and I can zoom in and out correctly.
Now, I want to see scroll bars if the image is too big to show when I zoom in.
I've used the UI. I placed a QScrollArea. Inside, the QLabel.
The verticalScrollBarPolicy is ScrollBarAsNeeded.
The horizontalScrollBarPolicy is ScrollBarAsNeeded.
The problem is: it doesn't work. I zoom in, but no scrollbar appears.
Second try: using a layout inside the QScrollArea.
So now there's a QWidget between the QScrollArea and the QLabel: a horizontal layout.
Opened the same image, now I can see a vertical scroll bar on the right. The image is streched from left to right. When I zoom the image gets its correct proportion.
BUT... I zoom out and the scroll bar is the same, even if I can see the whole image. The horizontal scroll bar never appears.
Resizing the QLabel doesn't seem to affect. But if I resize the QScrollArea (resizing the main window) the horizontal scroll bar appears.
I've been checking some numbers:
In the QScrollArea
Its size changes: below 599 width (why this number? I can't see it anywhere) the horizontal bar appears.
sizeHint() always returns the same values: 33x41
In the QLabel
The dimensions change, but that doesn't affect.
sizeHint() always returns the same values: 560x1558
Here is the code in XML from the UI designer:
<widget class="QWidget" name="centralWidget">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>637</width>
<height>649</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="miImagen">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
What am I missing? Thank you.
I know this is an old post - but in case you or anyone is still having a problem, it might help to set QScrollArea::widgetResizable to false.
At least, when I tried a similar thing, my vertical scrollbar was always disabled (even though I set the size of the scrollable widget to have a height larger than the viewport) until I set this to false.
When it's true, I think it updates the size of the scrollable widget, thus the scrollbars should not be needed. This allows you to do what it does in the example I guess, and implement a stretch-to-fit function. (actually what I'm trying to do is fit to width, with just a vertical scroll bar)
Have you tried following Qt's scroll area example? If you're using a QLabel to display your image, then the use of QScrollArea is pretty much the standard way of achieving what you want. You use it like so (from the example):
imageLabel = new QLabel;
imageLabel->setBackgroundRole(QPalette::Base);
imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
imageLabel->setScaledContents(true);
scrollArea = new QScrollArea;
scrollArea->setBackgroundRole(QPalette::Dark);
scrollArea->setWidget(imageLabel);
setCentralWidget(scrollArea);
Then zooming is handled like so:
void ImageViewer::zoomIn() {
scaleImage(1.25);
}
void ImageViewer::zoomOut() {
scaleImage(0.8);
}
void ImageViewer::scaleImage(double factor)
{
Q_ASSERT(imageLabel->pixmap());
scaleFactor *= factor;
imageLabel->resize(scaleFactor * imageLabel->pixmap()->size());
adjustScrollBar(scrollArea->horizontalScrollBar(), factor);
adjustScrollBar(scrollArea->verticalScrollBar(), factor);
zoomInAct->setEnabled(scaleFactor < 3.0);
zoomOutAct->setEnabled(scaleFactor > 0.333);
}
void ImageViewer::adjustScrollBar(QScrollBar *scrollBar, double factor) {
scrollBar->setValue(int(factor * scrollBar->value()
+ ((factor - 1) * scrollBar->pageStep()/2)));
}
You can, of course, get a better idea of what's going on by looking at the example, but that's the gist of it. I think perhaps the adjustScrollBar() function might be the most helpful thing for you.
Your last comment on the original post is correct, the QScrollArea doesn't magically notice the change in size of its contents. Look at how the example uses adjustScrollBar() to compensate for this fact.

Resources